Hi, all
I have service and application. In some cases my service creates
Ongoing Notification in the Status bar. When user click it - my
application started. It is good, but sometimes my application is
already opened at this moment,
Tell me, please, what should I do to _switch_ to my application if it
is already opened, istead of creating new activity? I want to get the
same behavior as when I press application icon from the Application
list.
>From manifest:
<activity android:name="com.myapp.MyAppMainActivity
android:launchMode="singleTop">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Using code:
public static void startNotification(Context context, int resID, int
iconID, int titleTextID, int contentTextID) {
NotificationManager mNM =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence text = context.getText(contentTextID);
Notification notification = new Notification(iconID, text,
System.currentTimeMillis());
Intent activityToStart = new Intent(context,
MyAppMainActivity.class);
activityToStart.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
PendingIntent contentIntent =
PendingIntent.getActivity(context, 0, activityToStart, 0);
notification.setLatestEventInfo(context,
context.getText(titleTextID), text, contentIntent);
mNM.notify(resID, notification);
}
With greate hope,
Tina
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en