Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing values in Pending Intents Android

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?..

like image 527
gowri Avatar asked Dec 12 '12 05:12

gowri


People also ask

What is the use of pending intent in android?

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.

What is request code in pending intent?

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.

What is the difference between intent and 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.


1 Answers

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")
like image 118
G M Ramesh Avatar answered Oct 09 '22 10:10

G M Ramesh