murdoch201
Gebruiker
- Lid geworden
- 31 mei 2008
- Berichten
- 336
Hoi,
Ik heb wat problemen bij het maken van een notificatie voor een android app.
Ik wil dat hij de applicatie gewoon weer terug opent waar hij was gebleven wanneer de persoon op de notificatie klikt. Ik heb reeds tonnen aan forums afgelopen maar niks blijkt te werken.
Dit is wat ik nu heb:
Als ik hem nu draai werkt het ontvangen en optellen van notificaties perfect. Alleen als ik op de notificatie klik, crasht hij nu. Is afhankelijk van dit stukje:
Kan er iemand me helpen?
Groetjes,
murdoch201
Ik heb wat problemen bij het maken van een notificatie voor een android app.
Ik wil dat hij de applicatie gewoon weer terug opent waar hij was gebleven wanneer de persoon op de notificatie klikt. Ik heb reeds tonnen aan forums afgelopen maar niks blijkt te werken.
Dit is wat ik nu heb:
Code:
long[] vpattern = {200,200,100,400};
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Titeltje")
.setNumber(++messageNum)
.setOnlyAlertOnce(true)
.setAutoCancel(true)
.setDefaults (Notification.DEFAULT_SOUND)
.setVibrate(vpattern)
.setContentText("Berichtje");
// Creates an explicit intent for an Activity in your app
Context context = getApplicationContext();
Intent resultIntent = new Intent(context, MainActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(MainActivity.this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(2435, mBuilder.build());
Als ik hem nu draai werkt het ontvangen en optellen van notificaties perfect. Alleen als ik op de notificatie klik, crasht hij nu. Is afhankelijk van dit stukje:
Code:
Context context = getApplicationContext();
Intent resultIntent = new Intent(context, MainActivity.class);
Kan er iemand me helpen?
Groetjes,
murdoch201