I'm developing an app which consists of two library projects. Both library projects are used by the actual app.
The first library project can be seen as the main library project as it contains the main menu in form of a dashboard for the whole app. From one entry in the dashboard the user can start an activity which is part of the second library project.
All activities and any further once that can be started from this activity are also part of the second library project. So the second library project doesn't know anything about the first one.
At the end of the action flow the user should return to the dashboard activity by clicking a single button. So I need to clear the whole activity stack excluding the first activity (dashboard). Normally I would do this by starting the Dashboard activity with the flag FLAG_ACTIVITY_CLEAR_TOP. Also using FLAG_ACTIVITY_NO_HISTORY won't be an option as I need the history.
But as I mentioned before none of the components of the second library project should not know anything about the main library project. So calling the Dashboard activity with the flag is no solution.
So I'm looking for a way to finish all activities of the second library project but not the dashboard activity from the main library project.
When your dashboard calls the second activity, bundle the class name(as a string) in an intent. In your second activity, you can use that class name to create the intent to return.
Use MyActivity.getClass().getName()
to form the string.
Use Class.forName(className)
to get the class back.
Edit: You may also need to grab the full package name for forName()
to work: .getClass().getPackage().getName()