CelinHC
CelinHC

Reputation: 1984

onActivityResult for PendingIntent

How do i get the result of an activity started from NotificationManager?

In other words i need to get the resultCode from a PendingIntent.

public void test(Context context){
    Notification notification = new Notification(null, "text", System.currentTimeMillis());
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.example.com"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
    notification.setLatestEventInfo(context, "text", "text", pendingIntent);
    notificationManager.notify(0, notification);
}

I want to be notified when the browser's activity ends.

OBS: This code is outside an activity, that's why it recieves the context as parameter

Upvotes: 4

Views: 4455

Answers (2)

dharmendra
dharmendra

Reputation: 7881

Let's see in simply way , IN Activity A :

intet.putStringExtra("from notification") ;

In Activity B:

if (getintent().getStringExtra("from notification") !=null ){
//TODO do what u want !
}

Upvotes: -1

inazaruk
inazaruk

Reputation: 74780

Let's assume you have activity A that sets PendingIntent. This PendingIntent calls activity B. You want receive result of B.

You can do this by introducing proxy activity: A -> PendingIntent -> ProxyActivity --> startActivityForResult --> B. This way you'll receive result from B into your ProxyActivity activity.

Note that you should call startActivityForResult() in ProxyActivity.onCreate().

Upvotes: 3

Related Questions