Question: Here is the code for back button. I want to kill other activities by back button but its not working in one activity, but I have other activities and without one activity its working fine. Please help me out. 

```
public void onClick(View v) {

    Intent intent = new Intent(getApplicationContext(),
                    SomeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

}

```

Answer: 
Might be this code will help you: 

```
public void onClick(View v) {
    Intent i = new Intent(getApplicationContext(), SomeActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(i);
    finish();
}

```
Try to define one local broadcast receiver on top most parent activity or base activity :

```
private final class KillReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    finish();
  }
} 

```

Intialize and register broadcast receiver in onCreate() and unregister in onDestroy() on top most parent activity or base activity :

private KillReceiver clearActivityStack;

```
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    clearActivityStack = new KillReceiver();
    registerReceiver(clearActivityStack, IntentFilter.create("clearStackActivity", "text/plain"));
}

@Override
protected void onDestroy() {
    super.onDestroy();
    unregisterReceiver(clearActivityStack);
}

```

Now call broadcast receiver when wan to clear all previous activity :

```
public void onClick(View v) {
    Intent clearIntent = new Intent("clearStackActivity");
    clearIntent.setType("text/plain");
    sendBroadcast(clearIntent);
    Intent intent = new Intent(getApplicationContext(),SomeActivity.class);
    startActivity(intent);
}

```