I have a alarm manager which is calling an activity class named ScheduleAlert.
public class ScheduleAlert extends ActivityGroup {
private String notificationAlart, editEventid;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...........
..........
// ************* Notification ************//
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.icon, "Myapp", nextAlarmTime);
Context context = getApplicationContext();
CharSequence contentTitle = "Myapp";
CharSequence contentText = notificationAlart;
Intent notifyIntent = new Intent(context, MyApp.class);
PendingIntent pendingIntent = PendingIntent.getActivity(ScheduleAlert.this, 0, notifyIntent,android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,pendingIntent);
notifyDetails.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_AUTO_CANCEL;
notifyDetails.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
mNotificationManager.notify((int) editEventid, notifyDetails);
// ************* Notification ************//
this.finish();
}
public void onDestroy(){
super.onDestroy();
}
}
I want that the indent of MyApp activity should fire when I tap on the notification massage. At the time of notification I want just sound and vibration. But now the I am getting the sound and vibration, and also the MyApp activity is fired, which I do not want actually. What is problem in my code?
There are lots and lots of strange things with this code:
ActivityGroupfor this codegetApplicationContext()in most circumstances, such as this oneActivityGroup(for whatever reason) and not aService, it is misleading to the OS and the user to haveFLAG_FOREGROUND_SERVICEFLAG_FOREGROUND_SERVICEandFLAG_AUTO_CANCELmake little sense in combinationHowever, I would not expect any of this to cause
MyAppto automatically start. In fact, AFAIK, there is no circumstance in which aNotificationwill automatically invoke itsPendingIntentwithout the user tapping on it. I suspect that your real problem lies elsewhere.