Data transfer between Android BroadcastReceiver, ContentProvider and Activity?

I developed an application that receives a broadcast, and then starts Activity, where it Activityasks ContentProvider which displays information from DNS in real time.

I would like to be able to shuffle this so that instead of going:

BroadcastReceiver.onReceive() {
  Intent intent = new Intent(...);
  intent.setData(...); // set a single String data
  context.startActivity(intent);
}

Activity.onCreate() {
  String value = intent.getData();  // get the String data
  Cursor = ContentProvider.query(search);
  ...
  setContentView(...);
}

he's coming:

BroadcastReceiver.onReceive() {
  Cursor = ContentProvider.query(...);
  if (cursor != null) {
     Intent intent = new Intent(...);
     // how do I pass the cursor?
     getContext().startActivity(intent);
  }
}

Activity.onCreate() {
  // how do I retrieve the cursor?
  setContentView(...);
}

i.e. if it query()does not return data, I want to skip the start Activityand allow the broadcast to pass as usual.

If it query()returns data, I want to Cursor Activity, so I do not need to go and request data again.

In turn, it Activityhas its own user interface, to which the user must respond.

Is it possible?

+5
2

, , , , . , , , , , .

BroadcastReceiver.onReceive() {
  Intent intent = new Intent(...);
  intent.setData(...); // set a single String data
  context.startActivity(intent);
}

Activity.onCreate() {
  String value = intent.getData();  // get the String data
  Cursor = ContentProvider.query(search);

  if(cursor.isEmpty() ...){
    finish();
    return;
  }
  ...
  setContentView(...);
}

, , , - . - , , , :)

, , - . Android onCreate() ( , onStart onResume ), , .

+5

, Serializable Parcelable ( aim.setExtra()). , , ?

0

All Articles