0

Assume that the application has two activities, namely Activity1 and Activity2. Activity1 is responsible to load some bunch of text and audio files. During the loading process Activity1 disposes progress dialog. After successfully loading, then comes the Activity2. In my application Activity1 must run only once. If the user presses back button on Activity2,then application must terminate. But what I have seen that, Activity1 comes to the screen if the back button is pressed. How can I achieve this? Is there any way to terminate application in the case of user presses back button on Activity2?

Any help will be appreciated.

Thanks

2 Answers2

7

You could just have finish() after you start intent for Activity2.

Intent intent = new Intent(this, Activity2.class);
startActivity(intent);
finish();
nhaarman
  • 98,571
  • 55
  • 246
  • 278
jsp
  • 2,546
  • 5
  • 36
  • 63
0

Your could override onActivityResult in Activty1 which will be called when Activity2 exits and returns control to it.

Then something like:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    finish();
}

Should close activity1 after activity2 is closed.

Elemental
  • 7,365
  • 2
  • 28
  • 33