Q:

Go back to specified screens only using back botton in android

App having screen1, screen2, screen3 , screen4
user can go to screen3 from remaining 3screens
if user clicks on back button in screen3 
then he should be redirected to screen1(if he comes from screen1) or screen2 (if he comes from screen2)
but should not go to screen4
i tried finish()  in screen3
functionality is missing
how can i solve this,
please help me 
Thank you in advance.

A:

You'll want to look into Intent flags.  Intent.FLAG_ACTIVITY_NO_HISTORY can be used so that you can't go back to an activity.

public static final int FLAG_ACTIVITY_NO_HISTORY 
Since: API Level 1
If set, the new activity is not kept in the history stack. As soon as the
  user navigates away from it, the activity is finished. This may also
  be set with the noHistory attribute.

