简体   繁体   中英

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 should 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM