0

I have a set of some activities which co-ordinate with each other to complete some transaction..
After the transaction is complete I am redirected to the first activity again for a new transaction...
what I want is after completing of the transaction..when I am redirected to first activity, the app should close when I press the back key, i.e, I don't want to see the previous transaction and it should appear like the application has just started.. What should be done for that???

Also I don't want to finish() the activities when the transaction is going on....After the completion of transaction only all the activities from previous transaction should be killed...
And Also startActivityForResult() is not going to solve my problem.

Suggest your answers please..

hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
  • 1
    You can register a BroadCastReceiver and send a broadcast. [Have a look at this one](http://stackoverflow.com/a/11430509/726863) – Lalit Poptani Aug 18 '12 at 05:36

3 Answers3

1

Why don't you override the back-button pressed method and then do whatever you want the app to behave like you want it to . Override the onBackPressed() method and if you want the app to start again then create an intent that fires up your first activity or do finish() if you want to close the app (but you dont want to do that either)

hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
Android2390
  • 1,150
  • 12
  • 21
1

an Easy way to do that:

in the first activity use public static variables.

and change them from the other activites mainActivity.VariableName = "whatever" when you return to the main activity you will have all the data you want.

Hossam Alaa
  • 663
  • 5
  • 9
0

Use below steps:

  1. Take a static boolean variable in your FirstActivity

    public static boolean killApplication = false;

  2. Override onBackPressed method in your FirstActivity like

    public void onBackPressed()
    {
        super.onBackPressed();
    
        FirstActivity.killApplication = true;
    
    }
    
  3. Override onResume method in all Activities like

     protected void onResume()
     {      
         if (FirstActivity.killApplication) 
         {
             finish();
         }
     }
    
  4. set killApplication = false in your FirstActivity onCreate() method.

Vivek Kumar Srivastava
  • 2,158
  • 1
  • 16
  • 23