Reputation: 1959
In my android application, I have an activity called A .From A, I call a background service.In that services onStartCommand
I will do some AsyncTask
and Provided an Intent to move to another activity called B. Where I am stuck is,
1. How can I stop the service itself after calling the Intent?
EDIT: I tried calling StopSelf();
but it not ending my service.
2. After reaching B the back button should not work. Currently if press backbutton I can still go to Activity A.
My Intent
Intent dialogIntent = new Intent(UserLoginValidationService.this,SplashScreen.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
stopSelf();
startActivity(dialogIntent);
EDIT: How to call finishAffinity();
in service?
Any help is appreciated.
Upvotes: 0
Views: 150
Reputation: 146
This could be the best way to do it.
NOTE: unregister BroadcastReceiver in A Activity onDestroy() method.
stopSelf() do stop the service but it could take little time. You can cross check it by putting log in onDestroy() Method of Service.
Upvotes: 7
Reputation: 1709
1. How can I stop the service itself after calling the Intent?
You can stop service using stopSelf()
.
2. After reaching B the back button should not work. Currently if press backbutton I can still go to Activity A.
If you want to close the application on back button press then you should open at Activity B clearing previous activity.
Upvotes: 1