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?

2
  • why don't you just start the activity A from activity C with an intent? Jan 27, 2014 at 10:28
  • @fedorSmirnov then on click of back it will call again Activity C
    – PPD
    Jan 27, 2014 at 10:29

2 Answers 2

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.

1

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.