1

I have a problem with sending extras with Pending Intent. I'm adding extra String in my StateCh service and sending to my MainActivity. MainActivity starts as expected but the extra String I have put there is always missing.

MainActivity.java:

public class MainActivity extends Activity {

 public void onResume() {
    super.onResume();

 String recMessage = this.getIntent().getStringExtra("message");

 if(recMessage.equals("")) {
    Log.v("recMessage", "none");
  } else {
   Log.v("recMessage", "something");
  }
    // ..
 }
}

StateCh.java:

public class StateCh extends Service {

//...

   private void notificationU(String title, String text)  {

    //The intent to launch when the user clicks the expanded notification
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra("message", "ssss");
    intent.setAction("actionstring" + System.currentTimeMillis());

    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

     Notification noti2 = new NotificationCompat.Builder(this)
     .setContentTitle(title)
     .setContentText(text)
     .setSmallIcon(R.drawable.warning)
     .setContentIntent(pendIntent)
     .build();

     mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     mNotificationManager.notify(123456, noti2);
    }

    // ...      

}
XorOrNor
  • 8,868
  • 12
  • 48
  • 81

2 Answers2

1

check using TextUtils

if (!TextUtils.isEmpty(recMessage)) {

// here your require condition

}
Ankitkumar Makwana
  • 3,475
  • 3
  • 19
  • 45
  • This is not reason of the problem. if I replace this checkin code with `Log.v("message=",recMessage);` I would get `message=`. – XorOrNor May 14 '13 at 07:55
0

I have found the right answer for my problem asking one more time and more precisely in another topis, here: Pending intent extras are received only when activity is paused .Maybe it will help someone.

Community
  • 1
  • 1
XorOrNor
  • 8,868
  • 12
  • 48
  • 81