开发者

Not finish the activity use theme dialog

开发者 https://www.devze.com 2023-03-05 10:01 出处:网络
here is my code @Override public void onCreate(Bundle savedInstanceState) { super.onCreat开发者_StackOverflow社区e(savedInstanceState);

here is my code

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreat开发者_StackOverflow社区e(savedInstanceState);
        AlertOn();
    }

    private void AlertOn() {    
         alertbox = new AlertDialog.Builder(this).create();
        alertbox.setIcon(R.drawable.icon);
        alertbox.setTitle(getIntent().getStringExtra("Title"));
        alertbox.setMessage(getIntent().getStringExtra("Message"));
        alertbox.setButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(final DialogInterface dialog, int arg1) {               
                dialog.dismiss();
                Intent startActivity = new Intent(); 
                startActivity.setClass(getApplicationContext(), moontech.fax.mFax.class); 
                startActivity.setAction(NotificationAlert.class.getName()); 
                startActivity.setFlags( 
                        Intent.FLAG_ACTIVITY_NEW_TASK 
                        | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);      
                 startActivity(startActivity);
                 finish();
            }
        });

        alertbox.show();        
    }

and in manifeast file declare

<activity android:name="com.demo.notificationalert"
            android:theme="@android:style/Theme.Dialog" 
            android:screenOrientation="portrait" />

but when display dialog and without press ok i use back from device then that activity not finished.


By default, when a dialog is showing and you press the back button, it closes your dialog. You can override the onKeyDown method in your activity like this:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        finish();
    }
    return super.onKeyDown(keyCode, event);
}

This will finish your activity. Hope it helps.

0

精彩评论

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