Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finish (Close) a Android Activity on Touch

Tags:

android

How to terminate an Activity in Adroid on touch. Here i shows a view which is described in details.xml. I need to dismiss the activity on touch. I tried the following code. But its not working. Any ideas?

public class Details extends Activity {
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.details);
    }
    public boolean onTouchEvent(MotionEvent event){
        this.finish();
        return true;
    }       
}
like image 789
dinesh707 Avatar asked Sep 13 '25 19:09

dinesh707


1 Answers

You should use

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    finish();
    return super.dispatchTouchEvent(ev);
}
like image 194
Addev Avatar answered Sep 16 '25 09:09

Addev