Bonjour,

Depuis quelques jours je suis en face d'un problème que je n'arrive pas à résoudre, j'ai un application qui reçoit des notification via GCM jusqu'a la tout va bien et je bien le message dans ma notification. Mais le problème est lorsque que je clique sur ma notification et que sa ouvre l'Acitivity en questions la fonction getStringExtra() me renvoie souvent la même chose que la notification précédente alors que dans ma notification le message à bien changer.

Pour mieux comprendre voici le traitement quand la notification arrive sur le service :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
private void sendNotification(String greetMsg) {
        String sMsg = "";
        String sNotifMsg = "";
        int iTypeNotif=0;
        Date now = new Date();
        notifyID = now.getTime();
 
        Intent resultIntent = new Intent(this, NotifAcitivity.class);
        resultIntent.putExtra("greetjson", greetMsg); // ON PASSE BIEN LE MESSAGE
        resultIntent.setAction(String.valueOf(notifyID));
        resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), (int) notifyID,
                resultIntent, 0);
 
        NotificationCompat.Builder mNotifyBuilder;
        NotificationManager mNotificationManager;
 
        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 
        JSONObject jsonObj = null;
        try {
            jsonObj = new JSONObject(greetMsg);
            sMsg = jsonObj.getString("msg");
            Log.v(Constantes.TAG, "MESSAGE = "+sMsg);
 
            // Récuperer le type de notfif
            Log.v(Constantes.TAG, ProcedureGlobale.getParams("TYPE_NOTIF",sMsg)); // ICI J'AI BIEN LE MESSAGE QUI CHANGE
            iTypeNotif = Integer.parseInt(ProcedureGlobale.getParams("TYPE_NOTIF",sMsg));
 
            switch (iTypeNotif){
                case Constantes.TYPE_MSG:
                    sNotifMsg = "Vous avez une message d'utilisateur.";
                    break;
                case Constantes.TYPE_TEMPS:
                    sNotifMsg = "Un de vos compte arrive à terme.";
                    break;
                case Constantes.TYPE_AMENDE:
                    sNotifMsg = "Vous avez une amende.";
                    break;
            }
 
        } catch (JSONException e) {
            e.printStackTrace();
        }
 
 
        mNotifyBuilder = new NotificationCompat.Builder(this)
                .setContentTitle("Notification")
                .setContentText(sNotifMsg)
                .setSmallIcon(R.drawable.ic_launcher);
        // Set pending intent
        mNotifyBuilder.setContentIntent(resultPendingIntent);
 
        // Set Vibrate, Sound and Light
        int defaults = 0;
        defaults = defaults | Notification.DEFAULT_LIGHTS;
        defaults = defaults | Notification.DEFAULT_VIBRATE;
        defaults = defaults | Notification.DEFAULT_SOUND;
        defaults = defaults | Notification.FLAG_AUTO_CANCEL;
 
        mNotifyBuilder.setDefaults(defaults);
        // Set the content for Notification
        mNotifyBuilder.setContentText(sNotifMsg);
        // Set autocancel
        mNotifyBuilder.setAutoCancel(true);
        // Post a notification
        mNotificationManager.notify((int)notifyID, mNotifyBuilder.build());
    }
Donc comme je l'ai dit ici le message de ma notification change bien dans le log.v et il est bien passer dans le putString();

Mais ensuite dans mon Activity ci-desous le getStringExtra() me renvoie parfois des message d'une ancienne notification :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notif_acitivity);
        String sRetour = null;
        String json = getIntent().getStringExtra("greetjson");
        Log.v(Constantes.TAG, "Json = " + json);
        sRetour = Constantes.PARAM_TYPE_ECHAN + "NOTIF;";
Avez-vous une petite idée, j'ai pourtant bien un id différent pour chaque notification. Merci d'avance pour votre aide.