Notify other activities of the same application to finish it self from one activity
I'm working on an application which have 5 activities and any of the activity can access other 4. In one of the activities i have a Finish
button that shou开发者_StackOverflow中文版ld put my application on background thread. I want to notify my other activities to call finish()
, and for that i have two ideas in mind. One is by using intent
but other is using interface
but i'm little confused to decide on which way should i go?
Are there any other way to notify all activities on same application from an event of one activity?
Thanks
Why don't you just call ((Activity) context).finish();
where context
is the context of the activity you want to call finish()
on.
I got finally what i wanted, I need to send the whole application in background and stop all services used.. Stopping services was a lot easier than I had thought at the time when I asked the question.
And sending application in background is even easier because there is an sdk supported method to send an application to background
ActivityClass.moveTaskToBack(true);
If you are in activity class you can directly call the method.
Here is the documentation of the method
If false then this only works if the activity is the root of a task; if true it will work for any activity in a task.
in Finish onclick function call finish() of all the other Activities ie
(activities which u wanna close).finish()
Hope this will help
精彩评论