Reanudar una actividad cuando se hace clic en una notificación

He hecho una aplicación que gestiona sms, he creado las notificaciones pero cuando hago clic en ellas inicia otra actividad, me gustaría saber cómo comprobar si se ha detenido una actividad y reanudarla.

Aquí está el código usado para crear el pendienteintent:

private void createNotification(SmsMessage sms, Context context){ final NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); String contentTitle = ""; // construct the Notification object. final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(contentTitle) .setContentText(sms.getMessageBody()) .setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(getIconBitmap()) .setNumber(nmessages); builder.setAutoCancel(true); //(R.drawable.stat_sample, tickerText, // System.currentTimeMillis()); // Set the info for the views that show in the notification panel. //notif.setLatestEventInfo(this, from, message, contentIntent); /* // On tablets, the ticker shows the sender, the first line of the message, // the photo of the person and the app icon. For our sample, we just show // the same icon twice. If there is no sender, just pass an array of 1 Bitmap. notif.tickerTitle = from; notif.tickerSubtitle = message; notif.tickerIcons = new Bitmap[2]; notif.tickerIcons[0] = getIconBitmap();; notif.tickerIcons[1] = getIconBitmap();; */ // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, BasicActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // Because clicking the notification opens a new ("special") activity, there's // no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity( context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT ); // Ritardo in millisecondi builder.setContentIntent(resultPendingIntent); nm.notify(R.drawable.ic_drawer, builder.build()); 

Necesitas establecer banderas en tu PendingIntent … como FLAG_UPDATE_CURRENT.

Aquí está todo en él. http://developer.android.com/reference/android/app/PendingIntent.html

Editar 1: No entendí la pregunta.

Aquí hay enlaces a temas que tuvieron el mismo problema pero se resuelven:

Reanudar una actividad de una notificación

Actividad de reanudación de notificaciones

Intención de reanudar una actividad previamente detenida (llamada desde una notificación)

Android: reanudar la aplicación desde la posición anterior

Por favor, lea las respuestas anteriores para una solución completa y hágamelo saber si funciona.

La única solución que realmente funcionó para mí después de hacer un montón de búsqueda es hacer lo siguiente:

Aquí usted está lanzando simplemente de la aplicación que guarda la pila actual:

 //here you specify the notification properties NotificationCompat.Builder builder = new NotificationCompat.Builder(this).set...(...).set...(..); //specifying an action and its category to be triggered once clicked on the notification Intent resultIntent = new Intent(this, MainClass.class); resultIntent.setAction("android.intent.action.MAIN"); resultIntent.addCategory("android.intent.category.LAUNCHER"); PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); //building the notification builder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, builder.build()); 

Prueba con esto.

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( mContext).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(mContext.getString(R.string.notif_title)) .setContentText(mContext.getString(R.string.notif_msg)); mBuilder.setAutoCancel(true); // Set notification sound Uri alarmSound = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); Intent resultIntent = mActivity.getIntent(); resultIntent.addCategory(Intent.CATEGORY_LAUNCHER); resultIntent.setAction(Intent.ACTION_MAIN); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pendingIntent); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(mId, mBuilder.build()); 
FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.