状态栏通知必须打开我正在运行的Activity,并且完美无缺。但..
当我从谷歌播放下载我的应用程序时,我的状态栏工作错误(启动新活动)...如果我从我的电脑下载应用程序并安装,状态栏通知工作完美。 我做错了什么? 我的应用程序主屏幕上的快捷方式可能有问题?当我从谷歌播放安装应用程序时他出现,如果我删除快捷方式并从菜单启动应用程序,我的应用程序工作完美。
/** Updates the notification. */
void updateNotification(String text) {
Intent mintent = new Intent(getApplicationContext(), MainActivity.class);
mintent.setAction(Intent.ACTION_MAIN);
mintent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(),
0, mintent, PendingIntent.FLAG_UPDATE_CURRENT);
mNotification.setLatestEventInfo(getApplicationContext(),
"Radio", text, pi);
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
}
/**
* Configures service as a foreground service. A foreground service is a
* service that's doing something the user is actively aware of (such as
* playing music), and must appear to the user as a notification. That's why
* we create the notification here.
*/
void setUpAsForeground(String text) {
Intent mintent = new Intent(getApplicationContext(), MainActivity.class);
mintent.setAction(Intent.ACTION_MAIN);
mintent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(),
0, mintent, PendingIntent.FLAG_UPDATE_CURRENT);
mNotification = new Notification();
mNotification.tickerText = text;
mNotification.icon = R.drawable.ic_stat_name;
mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
mNotification.setLatestEventInfo(getApplicationContext(),
"Radio", text, pi);
startForeground(NOTIFICATION_ID, mNotification);
}
清单
<activity
android:name="fm.radio.MainActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
答案 0 :(得分:0)
android:launchMode=«singleTop»