安卓通知栏打开最后一个活动活动? [英] Android notification bar open last active activity?
问题描述
我想我有一个问题,但我不能设法解决这个问题:(
我创建像定时器应用程序,当我启动定时器我选择去到Android主页或启动任何其他活动。
当我启动定时器我设置了通知栏图标,如果我使用其他应用程序(指从开始计时活动去),现在我需要去回到我的previously开始计时活动通过点击通知图标???
当我点击我开始一个新的实例计时器的活动,而不是previously开始计时活动! ,如果我再单击后退按钮,它告诉我一个previously定时器活动。
问题是:如何调用previously开始活动低谷通知栏,无法启动该活动的新实例??
这就是我下面的code样品:</ P>
私人无效notificationBar()
{
字符串NS = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager =(NotificationManager)getSystemService(NS);
INT图标= R.drawable.ico;
CharSequence的tickerText =一些称号......;
时长= System.currentTimeMillis的();
通知通知=新的通知(图标,tickerText时);
上下文的背景下= getApplicationContext();
CharSequence的contentTitle =一些应用题;
CharSequence的contentText =...的一些信息!;
意图notificationIntent =新的意图(这一点,main.class);
PendingIntent contentIntent = PendingIntent.getActivity(此,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL);
notification.setLatestEventInfo(背景下,contentTitle,contentText,contentIntent);
mNotificationManager.notify(NOTIF_ID,通知);
}
私人无效notificationClose(INT notifID)
{
字符串NS = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager =(NotificationManager)getSystemService(NS);
mNotificationManager.cancel(notifID);
}
我找到了答案这是关于标志: <一href="http://stackoverflow.com/questions/2424488/android-new-intent-starts-new-instance-with-androidlaunchmodesingletop">Android:新意图()开始与Android新实例:launchMode =&QUOT; singleTop&QUOT;
意向意图=新的意图(背景下,YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
I think I have a problem but I can't manage to solve it :(
I am creating like timer application and when I start timer I have option to go to android Home or start any other activity .
When I start timer I set a notification bar icon and if i use some other application (mean go from started timer activity) and now I need to go to back to my previously started timer activity by clicking on notification icon ???
When I click I am starting a new instance timer activity , not the previously started timer activity ! , and if I then click back button it show me a previously timer activity ..
Question is: How to call previously started activity trough notification bar , not to start new instance of that activity ??
This is sample of my code below :
private void notificationBar()
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ico;
CharSequence tickerText = "some title...";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "some app title";
CharSequence contentText = "...some info !";
Intent notificationIntent = new Intent(this, main.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTIF_ID, notification);
}
private void notificationClose(int notifID)
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.cancel(notifID);
}
I found an answer it's about flags : Android: new Intent() starts new instance with android:launchMode="singleTop"
Intent intent= new Intent(context, YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
这篇关于安卓通知栏打开最后一个活动活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!