Click here to Skip to main content
15,867,906 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey ,
I am currently working on an android application that involves closing an activity from a service. Any help on this matter is appreciated. Thanks.
Posted
Updated 20-Mar-16 21:07pm
Comments
Sandeep Mewara 24-Oct-12 10:58am    
What kind of help you are expecting of?
You went through this: http://developer.android.com/reference/android/app/Service.html
KASI KARUPPIAH 24-Oct-12 13:36pm    
Thanks man i already surfed through the page http://developer.android.com/reference/android/app/Service.html

what i really want to accomplish is

say i have a background service X and an activity A . I'd like to kill activity A from service X. How to accomplish this ....

1 solution

Add a broadcast receiver inside the activity.
Java
public class AnActivity extends Activity {
@Override
	protected void onCreate(Bundle savedInstanceState) {
       registerReceiver(mMessageReceiver, new IntentFilter("fgsdgdfgg"));
}

   private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {

			finish();
		}

	};
@Override
	public void onDestroy() {
		super.onDestroy();
		unregisterReceiver(mMessageReceiver);
	}
}

Send broadcast from service and in
onReceive()
method call
finish();


inside service handleintent method do as follows-
Intent intent1 = new Intent("fgsdgdfgg");
sendBroadcast(intent1);
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900