Android 处理同一活动的多个通知
我有一个广播多个通知的服务。每个人都开始相同的活动。因此,如果您有3个通知,第一个通知将打开活动并完美地工作。如果我关闭应用程序,然后单击下一个通知,它将完美启动。但是,如果我保持应用程序打开并单击我的下一个通知,则不会发生任何事情 应用程序是一个活动我是否应该进行另一个活动来处理这些通知 通知方式:Android 处理同一活动的多个通知,android,android-activity,service,notifications,broadcastreceiver,Android,Android Activity,Service,Notifications,Broadcastreceiver,我有一个广播多个通知的服务。每个人都开始相同的活动。因此,如果您有3个通知,第一个通知将打开活动并完美地工作。如果我关闭应用程序,然后单击下一个通知,它将完美启动。但是,如果我保持应用程序打开并单击我的下一个通知,则不会发生任何事情 应用程序是一个活动我是否应该进行另一个活动来处理这些通知 通知方式: private void sendNotification(ItemRunning item, int size) { Intent intent = new Intent(Singlet
private void sendNotification(ItemRunning item, int size) {
Intent intent = new Intent(Singleton.getAppContext(), MainActivity.class);
Bundle bundle = new Bundle();
bundle.putString("ALARM", item.getPrefName());
bundle.putString("NAME", item.getDisplayName());
intent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(Singleton.getAppContext(), Integer.valueOf(item.getPrefName()), intent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(Singleton.getAppContext())
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(item.getDisplayName())
.setContentText("You have " + String.valueOf(size) + " results.");
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) Singleton.getAppContext().getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(Integer.valueOf(item.getPrefName()), mBuilder.build());
Log.d(TAG, "sent alert " + String.valueOf(size) + " id = " + item.getPrefName());
}
关于新意图:
@Override
protected void onNewIntent(Intent intent) {
Log.d(TAG, "onNewIntent");
Bundle bundle = intent.getExtras();
if (bundle != null && bundle.getString("ALARM") != null) {
initializeResults(bundle);
} else {
super.onNewIntent(intent);
}
}
舱单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application
android:name=".Singleton"
android:allowBackup="true"
android:alwaysRetainTaskState="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:theme="@style/Theme.MAINTHEME">
<service android:name="service.MainService" />
<receiver android:name="service.MainBroadcastReceiver" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.MAINTHEME"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
overrideonNewIntent
添加了它,但什么也没有发生。甚至连日志都没有。宣言中的launchMode
是什么singleTop
?是的android:launchMode=“singleInstance”overrideonNewIntent
添加了它,没有任何事情发生。甚至连日志都没有。宣言中的launchMode
是什么singleTop
?是安卓:launchMode=“singleInstance”