开发者

Avoid Killing of Activity in Android

开发者 https://www.devze.com 2023-03-16 15:40 出处:网络
I want create an Activity in Android 开发者_开发问答which never kill (on long press of Back Button)until specific condition fulfill.

I want create an Activity in Android 开发者_开发问答which never kill (on long press of Back Button) until specific condition fulfill.

How I can achieve this ?

Thanks.


You could override the back button and only let the activity finish if the 'conditions have been met'.

@Override
public void onBackPressed() {
    if(conditionIsMet) {
         //The condition was met, close the activity
         finish;
    } else  { 
         //Cancel the button press
         return;
    }
}

I hope this is the answer you were looking for, but your question wasn't too clear.

0

精彩评论

暂无评论...
验证码 换一张
取 消