Passing values in Pending Intents Android

android, android-intent, android-pendingintent, background-process

Solution

Yes you can pass variables in pending Intent like the following:

            Intent in = new Intent(context, DemoActivity.class );
            in.putExtra( "notification_id", REGISTER_NOTIF_ID);  
            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            in.putExtra("2", Variable);
            in.putExtra("1", Variable);
            in.putExtra("IMData", Variable);
            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, in, 0);

and do the following in your onCreate of your DemoActivity class:

    Bundle extras = getIntent().getExtras();

    userGetId = extras.getString("2");
    userNameRecv = extras.getString("1");
    userFriendId = extras.getString("IMData")

Problem

Can we pass the arguments in a pending intent for the Background Process.. ``` Intent ij = new Intent(context,DemoActivity.class); PendingIntent operation = PendingIntent.getActivity(getBaseContext(),0,ij,Intent.FLAG_ACTIVITY_NEW_TASK); AlarmManager alarmManager = (AlarmManager) getBaseContext().getSystemService(ALARM_SERVICE); GregorianCalendar calendar = new GregorianCalendar(y, m, d,hr, mi); long alarm_time = calendar.getTimeInMillis(); alarmManager.set(AlarmManager.RTC_WAKEUP,alarm_time,operation); ``` In this, i'm using the alarm manager for starting the background process. By using this method, can i pass any variables or arguments? ``` public class DemoActivity extends FragmentActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /** Creating an Alert Dialog Window */ AlertDemo alert = new AlertDemo(); /** Opening the Alert Dialog Window */ alert.show(getSupportFragmentManager(), "AlertDemo"); } } ``` And in Alert Demo class i just use an alert box.. Now help me, where to place the Put Exatra method?..

Original source