cppdev cppdev - 5 months ago 28
Android Question

Android moving back to first activity on button click

I am writing a application where I am dealing with 4 activities, let's say A, B, C & D. Activity A invokes B, B invokes C, C invokes D. On each of the activity, I have a button called "home" button. When user clicks on home button in any of the B, C, D activities, application should go back to A activity screen ?

How to simulate "home" button in this case ?

button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        startActivity(new Intent(D.this, A.class));

Declare A in your manifest with the android:launchMode="singleTask". This way, when you call startActivity() from your other activies, and A is already running, it will just bring it to the front. Otherwise it'll launch a new instance.