Question

In a interview someone asked me this question. Suppose there are 4 activities in application. He wants back button to work normally on first three activities(i.e. going to previous screen on back button press); except the last.

He wanted that, when he press back button on fourth activity(screen), user should go to Home Activity(Starting Screen or first screen). But the contents on Home Activity should be same when user went from first screen to second screen. So I think, I can't use Intent, as it will create new instance of Starting Activity.

Was it helpful?

Solution

He wanted that, when he press back button on last activity(screen), user should go to Home Activity(Starting Screen or first screen).

The interviewer should be interviewing for his or her own replacement, if (s)he thinks that hacking the BACK button this way is a good idea.

So I think, I can't use Intent, as it will create new instance of Starting Activity.

Add FLAG_ACTIVITY_REORDER_TO_FRONT or the combination of FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP to the Intent used with startActivity() to bring up your "home activity". Either will cause the existing "home activity" instance to come to the foreground. If you want all other activities to be destroyed, use the second approach (FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top