Jump to content

Lancer une application au clic sur une notification


K-you

Recommended Posts

Bonjour,

Je souhaite gérer le cas où l'utilisateur, lors d'un calcul long dans mon application revient au bureau. Dans ce cas, j'ai un receiver qui me permet de lancer une notification à la réception de l'information (qui vient du réseau). Depuis ce Receiver, je voudrais relancer l'activité sur laquelle se trouvait l'utilisateur au moment de son retour au bureau. Je procède donc de la manière suivante :

if (!MonActivity.isInForeground) {
  Resources resources = context.getResources();
  String identifier = intent
 .getStringExtra(MyActivity.PARAM_EXCHANGE_IDENTIFIER);
  // Do the graphical update or record data
   if (identifier.equals(MyActivity.EXCHANGE)) {
   SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(context);
   Resources res = context.getResources();
   NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   Notification notification = new Notification(R.drawable.ic_my_icon,
  res.getText(R.string.my_text), System.currentTimeMillis());
   notification.number++;
   PendingIntent pending = PendingIntent.getActivity(context, 0, new Intent(context, MyActivity.class), 0);
   notification.setLatestEventInfo(context, resources.getString(R.string.app_name),
  res.getText(R.string.my_text), pending);
   notification.ledARGB = Notification.DEFAULT_LIGHTS;
   notification.vibrate = new long[] {0,100,200,300};
   notification.sound = Uri.parse(appPrefs.getString(resources.getString(R.string.ringtonePrefs), ""));
   notificationManager.notify(resources.getString(R.string.app_name), MY_ID, notification);
  }
 }

Mais lorsque mon activité se lance, c'est une nouvelle instance avec les informations fixée à l'initialisation. Lorsque j'appuie sur la touche retour, je reviens à mon application avec les informations voulues. Je n'arrive pas à ne pas lancer la seconde instance.

Autre besoin, j'aimerais également que lorsque je clique sur ma notification, celle-ci disparaisse.

Je développe sur le système d'exploitation Android 4.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...