• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Intent keeps getting previous Bundle

Here's what I'm trying to obtain: I have a service that creates a thread for each request using java.util.Timer (each request creates a Timer object and sets a certain date the thread should wake up and process data). At the specified date, the service creates a notification passing it a PendingIntent that causes a Dialog to pop up. I pass this intent a different ID (as data) each time I create it, but inside the class creating the dialog, the ID is always the first ID that was passed to this intent.

The code:

In the ScheduledSMSSenderService class
Code:
private void notifySender(long smsId, String recipient, String about){
        Log.d("notifySender","smsid="+smsId);
        Intent i=new Intent(this,CheckBeforeDialog.class);
        i.putExtra(SMSRepository.ID, smsId);
        i.putExtra(SMSRepository.RECIPIENT, recipient);
        i.putExtra(SMSRepository.ABOUT, about);
        i.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
        sendNotification(CHECK_NOTIFICATION_ID,R.drawable.sms_check, "Send message?", "Send message \""+about+"\" to "+recipient+" ?",i);
    }
private void sendNotification(int notificationType,int image, String title, String body, Intent intent){
        Notification notification=new Notification(image,title,System.currentTimeMillis());
        Log.d("sendNotification","smsid="+intent.getExtras().getLong(SMSRepository.ID));
        PendingIntent pi=PendingIntent.getActivity(this, 0, intent, 0);
        notification.setLatestEventInfo(getApplicationContext(), title, body, pi);
        notification.defaults=Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
        notification.ledOnMS=300;
        notification.flags=Notification.FLAG_AUTO_CANCEL;
        notification.number=0;
        NotificationManager nm=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.notify(notificationType, notification);
    }
so far the ID is good

in the CheckBeforeDialog class:

Code:
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String about="";
        String recipient="";        
        Bundle extras = getIntent().getExtras();
        if (extras!=null){
            smsId=extras.getLong(SMSRepository.ID);
            about=extras.getString(SMSRepository.ABOUT);
            recipient=extras.getString(SMSRepository.RECIPIENT);
        }
        Log.d("CheckBeforeDialog.onCreate","dialog created smsid="+smsId);
        AlertDialog.Builder b=new AlertDialog.Builder(this);
        b.setTitle("SEND MESSAGE ?");
        b.setMessage("Send message \""+about+"\"\nto "+recipient+" ?");
        b.setPositiveButton(R.string.yes_btn_txt, new SendListener());
        b.setNegativeButton(R.string.no_btn_txt, new CancelListener());
        b.setNeutralButton(R.string.edit_btn_txt, new EditListener());
        dialog=b.create();
        
        connection=new ScheduledSMSSender_ServiceConnection();
    }
The entry in AndroidManifest.xml for CheckBeforeDialog

<activity
android:name=".control.CheckBeforeDialog"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:taskAffinity=""
android:theme="@android:style/Theme.Dialog"/>


The ID is not the one sent with the bundle. Why not? Is there a solution to this problem?

I am using API level 4 if, by any chance, it matters.

Thanks in advance.
 
Here's what I'm trying to obtain: I have a service that creates a thread for each request using java.util.Timer (each request creates a Timer object and sets a certain date the thread should wake up and process data). At the specified date, the service creates a notification passing it a PendingIntent that causes a Dialog to pop up. I pass this intent a different ID (as data) each time I create it, but inside the class creating the dialog, the ID is always the first ID that was passed to this intent.

The code:

In the ScheduledSMSSenderService class
Code:
private void notifySender(long smsId, String recipient, String about){
        Log.d("notifySender","smsid="+smsId);
        Intent i=new Intent(this,CheckBeforeDialog.class);
        i.putExtra(SMSRepository.ID, smsId);
        i.putExtra(SMSRepository.RECIPIENT, recipient);
        i.putExtra(SMSRepository.ABOUT, about);
        i.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
        sendNotification(CHECK_NOTIFICATION_ID,R.drawable.sms_check, "Send message?", "Send message \""+about+"\" to "+recipient+" ?",i);
    }
private void sendNotification(int notificationType,int image, String title, String body, Intent intent){
        Notification notification=new Notification(image,title,System.currentTimeMillis());
        Log.d("sendNotification","smsid="+intent.getExtras().getLong(SMSRepository.ID));
        PendingIntent pi=PendingIntent.getActivity(this, 0, intent, 0);
        notification.setLatestEventInfo(getApplicationContext(), title, body, pi);
        notification.defaults=Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
        notification.ledOnMS=300;
        notification.flags=Notification.FLAG_AUTO_CANCEL;
        notification.number=0;
        NotificationManager nm=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.notify(notificationType, notification);
    }
so far the ID is good

in the CheckBeforeDialog class:

Code:
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String about="";
        String recipient="";        
        Bundle extras = getIntent().getExtras();
        if (extras!=null){
            smsId=extras.getLong(SMSRepository.ID);
            about=extras.getString(SMSRepository.ABOUT);
            recipient=extras.getString(SMSRepository.RECIPIENT);
        }
        Log.d("CheckBeforeDialog.onCreate","dialog created smsid="+smsId);
        AlertDialog.Builder b=new AlertDialog.Builder(this);
        b.setTitle("SEND MESSAGE ?");
        b.setMessage("Send message \""+about+"\"\nto "+recipient+" ?");
        b.setPositiveButton(R.string.yes_btn_txt, new SendListener());
        b.setNegativeButton(R.string.no_btn_txt, new CancelListener());
        b.setNeutralButton(R.string.edit_btn_txt, new EditListener());
        dialog=b.create();
        
        connection=new ScheduledSMSSender_ServiceConnection();
    }
The entry in AndroidManifest.xml for CheckBeforeDialog

<activity
android:name=".control.CheckBeforeDialog"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:taskAffinity=""
android:theme="@android:style/Theme.Dialog"/>


The ID is not the one sent with the bundle. Why not? Is there a solution to this problem?

I am using API level 4 if, by any chance, it matters.

Thanks in advance.




Hello!
Probably you have solve this already.

Try this:
PendingIntent pi=PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Instead of what you have.

Maybe it can help someone else.
 
Back
Top Bottom