Passing Values โ€‹โ€‹Pending Android Intent

Can we pass arguments 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 use the alarm manager to start the background process. 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 the Alert Demo class, I just use the warning window. Now help me where to put the Put Exatra method? ..

+4
source share
1 answer

Yes, you can pass variables in pending intent, as shown below:

  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") 
+10
source

All Articles