0

In my application suppose I have 3 activities A,B,C.

In application from Activity A it goes to B and from B to C.

Now what I want is if user is at Activity C.

When it click button it should go to Activity B.I had achieved this by calling finish(). But in Activity C I am getting response from Server. Now what I want is after getting response activity A has to be called.(without storing history of activity B in stack). How to achieve this?

Avijit
  • 3,834
  • 4
  • 33
  • 45
PPD
  • 5,660
  • 12
  • 52
  • 86

2 Answers2

2

If you only want to destroy a specific Activity such as Activity B, you can use receiver for that.

// declare your receiver in ActivityB

private MyReceiver receiver;

// register your receiver in onCreate() to get broadcast
registerReceiver(receiver, new IntentFilter("DESTROY"));

// customize BroadcastReceiver to your need   
class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("DESTROY")) 
            finish();
    }
}

And in ActivityC, you can send a receiver to destroy ActivityB,

sendBrodcast(new Intent("DESTROY");

ActivityB will get this broadcast and finish itself.

Orhan Obut
  • 8,756
  • 5
  • 32
  • 42
1

Intent intent = new Intent(C.this,A.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);

Dakshesh Khatri
  • 639
  • 7
  • 12