android实现程序的后台运行 and 完全退出

   /***
     * 点击返回 后 弹出对话框  提示   关闭  还是  后台
     */
    public void quitAndshut() {

        new AlertDialog.Builder(MainActivity.this).setTitle("提示")//设置对话框标题

                .setMessage("退出将不能进行电话录音!")//设置显示的内容

                .setPositiveButton("完全退出", new DialogInterface.OnClickListener() {//添加确定按钮


                    @Override

                    public void onClick(DialogInterface dialog, int which) {//确定按钮的响应事件

                        // TODO Auto-generated method stub

                        finish();
                        // 这里加上 要 一起  干掉的  服务
                        final Intent intent = new Intent(MainActivity.this, MyTelRecordService.class);
                        intent.setAction("ITOP.MOBILE.SIMPLE.SERVICE.SENSORSERVICE");
                        stopService(intent);
                        final Intent WakeServiec = new Intent(MainActivity.this, WakeServiec.class);
                        WakeServiec.setAction("ITOP.MOBILE.SIMPLE.SERVICE.WakeServiec");
                        stopService(WakeServiec);
                        System.exit(0);
                    }

                }).setNegativeButton("后台运行", new DialogInterface.OnClickListener() {//添加返回按钮


            @Override

            public void onClick(DialogInterface dialog, int which) {//响应事件

                // TODO Auto-generated method stub
                moveTaskToBack(false);
//            Log.i("alertdialog"," 请保存数据!");

            }

        }).show();//在按键响应事件中显示此对话框

    }

你可能感兴趣的:(android,之路)