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?..
A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it.
1- requestCode is used to get the same pending intent later on (for cancelling etc) 2- Yes, they will get override as long as your specify the same Receiver to your Intent that you specify on your PendingIntent.
In conclusion, the general and main difference between Intent and PendingIntent is that by using the first, you want to start / launch / execute something NOW, while by using the second entity you want to execute that something in the future.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With