My app contains two activity, one widget and a broadcast receiver.
First activity is default one which is called by home launcher. Second activity is a reminder dialog activity which plays a MP3 and has a dismiss button. It will appear on home screen.
My widget is a custom clock which setup an alarm to call a broadcast receiver every minutes which is responsible to update the clock. There are some reminders at specific time which broadcast receiver calls the reminder activity.
My app now is fully working, but there is a small problem: When app is open in the background (It's not on screen), when broadcast receiver start the reminder activity, the default activity comes first and reminder activity is shown over that. But when I close the app, reminder activity appears on home screen and there is no problem.
This is the code I use to startActivity from receiver:
context.startActivity(new Intent(context, ActivityReminder.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP));
And this is android manifest:
<activity android:name=".MyActivity"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".ActivityReminder" android:label="@string/reminder" android:screenOrientation="portrait" android:theme="@style/Theme.CustomDialog" />
<receiver android:name=".widget"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget" />
</receiver>
<receiver android:name=".UpdaterReceiver" />
For now I use this workaround in the default activity to solve the problem, it work just like closing the app:
@Override
protected void onPause()
{
super.onPause();
finish();
}
I found something more annoying. If the main activity is not closed, every call from broadcast receiver opens the activity again even it's open already. Although if the main activity is closed, subsequent call won't do anything.