调用onDestroy

时间:2017-03-21 14:37:33

标签: android android-activity activity-finish

我正在尝试终止该应用程序,但问题是调用onDestroy()并在该应用程序(相同的活动)重新启动之后。

你能告诉我这可能是什么原因吗?

请耐心等待我,我是android dev的新手。

public class MainActivity extends Activity {

    private MainViewModel mainViewModel;
    private ActivityMainBinding binding;

    private DrawerLayout drawerLayout;


    @Override
    public void sendBroadcast(Intent intent) {
        super.sendBroadcast(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View decorView = getWindow().getDecorView();

        /*int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        */


        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;/*
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;*/

        decorView.setSystemUiVisibility(uiOptions);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setContentView(R.layout.activity_main);

        initDataBinding();
        EpgScreenService epgScreenService = new EpgScreenServiceImpl();
        //epgScreenService.firstShow();

    }

    private void initDataBinding() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        mainViewModel = MainViewModel.getInstance(this);
        binding.setMainViewModel(mainViewModel);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerLayout.openDrawer(GravityCompat.START);

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //Do something after 100ms
                drawerLayout.closeDrawer(Gravity.LEFT);
            }
        }, 1200);

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

//        Toast.makeText(this,event.getKeyCode() + "", Toast.LENGTH_SHORT).show();
        if (keyCode == KeyEvent.KEYCODE_ENTER) {
            if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
                drawerLayout.closeDrawer(Gravity.LEFT);
            } else {
                drawerLayout.openDrawer(GravityCompat.START);
            }
        }
        if(keyCode == KeyEvent.KEYCODE_X){

            startActivity(new Intent(this,EpgActivity.class));

        }
        if(keyCode == KeyEvent.KEYCODE_Q){
            mainViewModel.stopPlayer();
            //android.os.Process.killProcess(android.os.Process.myPid());
            //finish();

            int pid = android.os.Process.myPid();
            android.os.Process.killProcess(pid);
            System.exit(0);
        }
        return super.onKeyDown(keyCode, event);
    }


/*

    @Override
    protected void onPause() {
        super.onPause();
        System.out.println("PAUSED");

        ActivityManager activityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);

        activityManager.moveTaskToFront(getTaskId(), 0);
    }
*/

    @Override
    protected void onResume() {
        super.onResume();
        System.out.println("RESSUMED");
        mainViewModel.setupPlayer();

    }

    @Override
    protected void onDestroy() {
        System.out.println("DESTROYING");
        super.onDestroy();
    }
}

0 个答案:

没有答案