-1

I have to stop my application after click the stop button. After some time Application class stating background. In application class i am staring multiple services (Each server again have thread to stat work).

Once user press the stop button i have to stop all services and stop the app. Three couple of way i tried but still after some time Application class calling.

MainActivity

1.stop button press ->finish() and tried finishAffinity(); 2. onDestopy -> system.exit ()

Srikanth
  • 584
  • 1
  • 6
  • 21
  • Post your `AndroidManifest` if you can. Either way, check this answer - https://stackoverflow.com/questions/14001963/finish-all-activities-at-a-time – Dayan Jul 11 '17 at 15:15

2 Answers2

0

There's not really a concept of stopping an Android app. Android has smarts about what to keep in memory and for how long. Don't try to out think it.

If you have services running, use stopService() (or stopSelf() internally) to tell Android they are stopped. If you have started threads in the services, ensure that you stop (Thread.interrupt()) those threads in the service's onDestroy() method.

For you activities, call finish(), and again, stop any threads started by the activity in it's onDestroy() method.

As a side note, properly stopping a thread is a topic all unto itself. Make sure you read up on that.

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
-1

U try to call "isFinishing()" method. and you refer below link

https://developer.android.com/reference/android/app/Activity.html

Kabilan
  • 191
  • 10
  • This is absolutely wrong. `onStop()` is a lifecycle method that's called by the framework and should never be called directly by an app. – Jeffrey Blattman Jul 11 '17 at 15:32
  • can u refer the below link.. https://developer.android.com/reference/android/app/Activity.html – Kabilan Jul 11 '17 at 15:35