4

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

CelinHC
  • 1,857
  • 2
  • 27
  • 36

2 Answers2

3

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().

inazaruk
  • 74,247
  • 24
  • 188
  • 156
-1

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 !
}
dharmendra
  • 7,835
  • 5
  • 38
  • 71