0

How to move from Activity A to Activity B without disturbing Activity A. On button click, I want to move to Activity B from Activity A, but i still want Activity A to run.

I dont want to use Service as i m not understanding it. Please tell me of any other way to do this..

Aaro247
  • 57
  • 1
  • 9

3 Answers3

0

When move from Activity A to Activity B. Activity A call onStop() method. So you can do what you want in the onStop().

    @Override
protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
//Do something here
}

All about Activity, refer to : http://developer.android.com/guide/components/activities.html

Tuan Vu
  • 6,397
  • 2
  • 14
  • 22
  • if i put my code in onStop(), it will run whenever i call any other activity. right? – Aaro247 Mar 27 '13 at 13:06
  • This won't keep the code running while in the other `Activity` it will run whatever code is in `onStop()` before showing the next `Activity` – codeMagic Mar 27 '13 at 13:24
0

From this answer:

Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
CurrentActivity.this.startActivity(myIntent);

The first activity will still exist when you start the second one. It won't be "running" but it'll call the onPause() method if Activity A is still visible underneath Activity B. If Activity A is no longer visible at all, it'll call the onStop() method.

You said you don't want to use a Service, but if you want to still have some part of Activity A running while a new activity is shown, I would consider using a Service or some kind of Threading that gets started in either the onPause() or the onStop() method of the activity.

Community
  • 1
  • 1
Wenger
  • 989
  • 2
  • 12
  • 35
0

You want to run a Service when ActivityA calls onPause() or onStop() then you can stop the Service in onResume() and resume your Activity from where the Service left off. See the Docs. You may not understand them but you need to take the time to read through about Services if you want it to function correctly. I believe there is even an example of this same thing in there. In onPause() you can call

This part of the docs will be extremely helpful in understanding also

codeMagic
  • 44,549
  • 13
  • 77
  • 93