Android: How do I avoid starting activity which is already in stack?

前端 未结 7 2160
一整个雨季
一整个雨季 2020-12-23 12:20

Lets try to explain my question: I got an application and a service. The application is started with activity A. The service sends a broadcast that will let the application

7条回答
  •  攒了一身酷
    2020-12-23 13:03

    You can use flag Intent.FLAG_ACTIVITY_NEW_TASK. If the activity is already running it will bring that to front instead of creating new activity.

    If you add Intent.FLAG_ACTIVITY_CLEAR_TOP with this, then all the activities after this activity in the backstack will be cleared.

提交回复
热议问题