tags:

views:

76

answers:

3

Actually i m little bit confused in Intent.

Suppose i have three activities. A,b,c and in activity A i have exit button. When i click on exit button my application finishes. I have one more button in A which is next button. Which take me to new activity. and in activity B i have two buttons next and back, and in activity C also i have two button out of which first takes me to A and Back button.

now i'm on C activity and want to go to A. where when i press exit it again takes me back to C instead of finish the application.

Why is this happening?

+1  A: 

Not really answering your question but your Android application just shouldn't have an Exit button. It's not necessary.

This blog post by Reto Meyer - a Google employee who works on Android - explains it well. This passage from it might be significant in relation to your problem:

In most cases the exit button simply calls Activity.finish. This is exactly equivalent to hitting the back button. Exactly.

Dave Webb
A: 

There is no Exit function in Android.

You probably want to bring up the Home application by it's corresponding Intent:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Pentium10
A: 

Exit button or not, Activity.finish only applies to the current activity and you are dealing with three different activities. Finishing activity A is simply taking you back in your stack to the previous activity C.

Check out the documentation on Activities and Tasks, launch modes, and clearing the stack for some explanation of what's going on in your example and what you can do to alter the behavior. I've always thought these sections of the Android documentation need to be enhanced or further explained but hopefully it will help a little.

Robert Nekic