简体   繁体   中英

Android - Resuming already running activity

I have an android application which has only one activity having only one button. When we press this button, another thread starts which does some particular work. If the button is again pressed, then the running thread stops. Now the problem is, if i leave the thread running and go to the home screen and again press the launcher icon of the app, it starts a new activity. Now if i click on the button of the activity, another thread starts. Now I have two threads running at the same time, which i don't want.

I want to reopen the previous running activity and then when I click on the button again, the already running should stop. I tried using launchmode: singleTask, singleInstance but nothing seems to be working.

Please help how to handle this problem.

Try reading the docs @ http://developer.android.com/guide/topics/manifest/activity-element.html

--

"singleTop"

Conditionally If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.

Alternatively

you can control the thread based on the onPause()/onCreate()/onResme(), pause in the onPause() create/start in the onCreate() restart the thread in the onResume()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM