【发布时间】:2012-02-11 20:34:45
【问题描述】:
我的 android 应用程序正在向前发展。我能够实现onDestroy() and onPause() 例程。
我还设法让 Android 的通知服务将带有标题和正文的图标放在通知栏/任务菜单中。
这个通知服务的唯一问题是,如果我的 android 应用程序已经在运行,并且已经启动了 super.onPause(); moveTaskToBack(true); 的 onPause() 函数,如果用户点击通知,它将弹出我的应用程序的新实例.
一旦用户与新实例交互,由于后台版本已经在运行,程序会崩溃,造成冲突。
这是我的通知代码,我需要帮助以使此代码查找我的应用程序的已运行版本:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificatonManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "app name";
long when = System.currentTimeMillis();
CharSequence contentTitle = "app title";
CharSequence contentText = "text";
Intent notificationIntent = new Intent(this, SuperMicProActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int signed = 1;
mNotificatonManager.notify(signed, notification);
我正在查看onResume(),可能是某种bringTaskToFront(this) 选项。这存在吗?
谢谢,
【问题讨论】:
-
没关系。我只是打开了我的 Manifest 文件并在我的
<activity标签中添加了android:launchMode="singleTop"。
标签: android android-emulator android-2.2-froyo android-notifications