Click the notification to not start a specific activity
source link: https://www.codesd.com/item/click-the-notification-to-not-start-a-specific-activity.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Click the notification to not start a specific activity
I am using a notification where I added an "action" which should start an activity.
I have two main activities: Login Activity and MainActivity. When the LoginActivity is started, it automatically logs in the user (if the user was previously logged in), does some other stuff, and then starts MainActivity. MainActivity is the host for several fragments.
Now when I add LoginActivity like this:
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);
Everything works fine. When I put MainActivity into the notificationIntent, a click on the notification does nothing.
How come?
EDIT:
Snippets from my manifest file:
<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>
try this :
PendingIntent contentIntent = PendingIntent.getActivity(getActivity(),0,PendingIntent.FLAG_UPDATE_CURRENT| PendingIntent.FLAG_ONE_SHOT);
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK