1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

Intent keeps getting previous Bundle


Last Updated:

  1. cristina_maria_botez

    cristina_maria_botez New Member This Topic's Starter

    Joined:
    Apr 29, 2010
    Messages:
    1
    Likes Received:
    0
    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 (Text):
    1.  
    2. private void notifySender(long smsId, String recipient, String about){
    3.         Log.d("notifySender","smsid="+smsId);
    4.         Intent i=new Intent(this,CheckBeforeDialog.class);
    5.         i.putExtra(SMSRepository.ID, smsId);
    6.         i.putExtra(SMSRepository.RECIPIENT, recipient);
    7.         i.putExtra(SMSRepository.ABOUT, about);
    8.         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);
    9.         sendNotification(CHECK_NOTIFICATION_ID,R.drawable.sms_check, "Send message?", "Send message \""+about+"\" to "+recipient+" ?",i);
    10.     }
    11. private void sendNotification(int notificationType,int image, String title, String body, Intent intent){
    12.         Notification notification=new Notification(image,title,System.currentTimeMillis());
    13.         Log.d("sendNotification","smsid="+intent.getExtras().getLong(SMSRepository.ID));
    14.         PendingIntent pi=PendingIntent.getActivity(this, 0, intent, 0);
    15.         notification.setLatestEventInfo(getApplicationContext(), title, body, pi);
    16.         notification.defaults=Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
    17.         notification.ledOnMS=300;
    18.         notification.flags=Notification.FLAG_AUTO_CANCEL;
    19.         notification.number=0;
    20.         NotificationManager nm=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    21.         nm.notify(notificationType, notification);
    22.     }
    23.  
    so far the ID is good

    in the CheckBeforeDialog class:

    Code (Text):
    1.  
    2. protected void onCreate(Bundle savedInstanceState) {
    3.         super.onCreate(savedInstanceState);
    4.         String about="";
    5.         String recipient="";        
    6.         Bundle extras = getIntent().getExtras();
    7.         if (extras!=null){
    8.             smsId=extras.getLong(SMSRepository.ID);
    9.             about=extras.getString(SMSRepository.ABOUT);
    10.             recipient=extras.getString(SMSRepository.RECIPIENT);
    11.         }
    12.         Log.d("CheckBeforeDialog.onCreate","dialog created smsid="+smsId);
    13.         AlertDialog.Builder b=new AlertDialog.Builder(this);
    14.         b.setTitle("SEND MESSAGE ?");
    15.         b.setMessage("Send message \""+about+"\"\nto "+recipient+" ?");
    16.         b.setPositiveButton(R.string.yes_btn_txt, new SendListener());
    17.         b.setNegativeButton(R.string.no_btn_txt, new CancelListener());
    18.         b.setNeutralButton(R.string.edit_btn_txt, new EditListener());
    19.         dialog=b.create();
    20.        
    21.         connection=new ScheduledSMSSender_ServiceConnection();
    22.     }
    23.  
    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.
     

    Advertisement
  2. blindado

    blindado New Member

    Joined:
    Sep 21, 2011
    Messages:
    1
    Likes Received:
    0



    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.
     

Share This Page

Loading...