【发布时间】:2014-04-04 08:49:01
【问题描述】:
我正在使用一个通知,其中我添加了一个应该启动一个活动的“动作”。
我有两个主要活动:登录活动和 MainActivity。当 LoginActivity 启动时,它会自动登录用户(如果用户以前登录过),做一些其他的事情,然后启动 MainActivity。 MainActivity 是多个 Fragment 的宿主。
现在当我像这样添加 LoginActivity 时:
Intent notificationIntent;
notificationIntent = new Intent(getActivity(), MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intentp =
PendingIntent.getActivity(getActivity(), 0, notificationIntent, 0);
NotificationCompat.Builder nBuilder;
Uri alarmSound = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
nBuilder = new NotificationCompat.Builder(getActivity())
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Smart Share - " + "")
.setLights(Color.BLUE, 500, 500).setContentText("message")
.setAutoCancel(true).setTicker("Notification from smartshare")
.setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
.setSound(alarmSound)
.setAutoCancel(true)
.setContentIntent(intentp);
NotificationManager nNotifyMgr = (NotificationManager) getActivity()
.getSystemService(getActivity().NOTIFICATION_SERVICE);
Notification not = nBuilder.build();
nNotifyMgr.notify(2 + 2, not);
一切正常。当我将 MainActivity 放入 notificationIntent 时,单击通知什么也不做。
怎么会?
编辑:
我的清单文件中的片段:
<activity
android:name="<packagename>.LoginActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="<packagename>.MainActivity"
android:label="@string/tab_title_mapview"
android:screenOrientation="portrait">
</activity>
【问题讨论】:
-
你能分享你的清单文件吗?
-
你想念 mManager.notify(100, notification);看我的回答
-
或者把所有代码发给你。
-
你的
mainActivity属于同一个包?试试这个nNotifyMgr.notify(1, not);
标签: android notifications action