Setting up Alarm Manager is creating 2 Instances of my Main Activity

前端 未结 3 2086
闹比i
闹比i 2020-12-06 23:51

I have 2 activities, a Main Activity and SetAlarm Activity. I call SetAlarm Activity from Main. When I set up the alarm I create an instance of my main. How do I set up the

3条回答
  •  误落风尘
    2020-12-07 00:12

    In default, an Activity can be instantiated multiple times on multiple tasks. If you want to keep it single, specify android:launchMode="singleTask" on the activity declaration in AnroidManifest.xml and override Activity#onNewIntent() on your main activity to receive a new intent from AlarmManager if main activity is already instantiated.

    See Tasks and Back Stack to learn more. You are facing almost same situation shown in Figure 3.

提交回复
热议问题