Many a times it is required that we jump back to the root activity. Something like popToRootViewController in IPhone world. For example I started activity A then B then C and from menu options I want to go to back to A. In this case instead of creating a new A activity, application design would need to pop out B and C and then refresh A with the new content.
To achieve this we can add a flag - FLAG_ACTIVITY_CLEAR_TOP to the intent while trying to launch the activity.
Small code snippet to go to the home activity
public static void goHome( Context ctx )
{
if ( ! ( ctx instanceof HomeActivity ) )
{
Intent intent = new Intent( ctx, HomeActivity.class );
intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );
ctx.startActivity( intent );
}
}
No comments:
Post a Comment