Reputation: 274
I have two applications such as Activity
and Service
. I start Service
from Activity
. When I exit the activity it stops but it is not completely getting stopped, running in background(Could see in Settings->ManageApplications
menu).
So I used android.os.Process.killProcess(android.os.Process.myPid())
in onDestroy
() function which completely terminates application. But the issue is that it also stops my service since it was started from my activity.i also tried using the below lines,
ActivityManager activityManager = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses(this.getApplication().getPackageName());
But still it stops my service since it will stop the associate processes as said in document.My question is that how can i terminate my activity completely without killing my service. Thanx in advance.
Scenario
Assume there are two applications 'a' & 'b'. I stop Application 'a' using finish()
call, 'a' closes successfully. Now I check the status of 'a' from 'b' using runningProcessInfo
call and i still find that application 'a' is running in the background.
Upvotes: 2
Views: 306
Reputation: 1006674
My question is that how can i terminate my activity completely without killing my service.
Call finish()
, which happens automatically when the user presses BACK (by default).
When i exit the activity it stops but it is not completely getting stopped, running in background(Could see in Settings->ManageApplications menu)
An application is not an activity. An application is a collection of components. In your case, your application consists of at least one activity and at least one service, based upon the information in your question.
So i used "android.os.Process.killProcess(android.os.Process.myPid())" in onDestroy() function which completely terminates application.
Do not do this.
Upvotes: 6