为什么在onPause()方法中销毁活动?

时间:2014-08-11 13:06:34

标签: android android-activity

如果用户在应用程序打开时没有在2分钟内执行任何操作,我想在暂停时显示超时弹出窗口。所以我试图在onpause()方法中处理它。当屏幕变黑时如果没有,则来到onpause()做了任何动作。但是当我的活动停止时,我的活动结束了。   我不知道为什么它发生了。如果删除了timeoutpopup()函数,那么它也无法正常工作。

   @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            Log.v("maintab oncreate", "oncreate");

            try {

                className = getIntent().getStringExtra("className");
                mPreferences = new ApplicationPreferences(MainTabActivity.this);
                mhandler = new Handler();
                checkFlagPresence = true;
                if (checkFlagFinish && !className.equals("verifyClass")) {
                    Log.v("exit aapp", "exit aapp");
                    checkFlagPresence = false;
                    finish();
                    Intent intent = new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_HOME);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);

                }

                requestWindowFeature(Window.FEATURE_NO_TITLE);
                setContentView(R.layout.tablayout);
                tabHost = getTabHost();
                Resources res = getResources();

                mLoginStatic = true;
                mUid = mPreferences.getPreference("uid", "");
                context = MainTabActivity.this;

                TabHost.TabSpec spec;
                Intent intent;

                intent = new Intent().setClass(MainTabActivity.this,
                        CalenderAlertActivity.class);
                spec = tabHost
                        .newTabSpec("calender")
                        .setIndicator("", res.getDrawable(R.drawable.cal_alert_tab))
                        .setContent(intent);
                tabHost.addTab(spec);

                intent = new Intent().setClass(MainTabActivity.this,
                        PHRAlertActivity.class);
                intent.putExtra("classHistoryName", "");
                spec = tabHost
                        .newTabSpec("phr")
                        .setIndicator("", res.getDrawable(R.drawable.phr_alert_tab))
                        .setContent(intent);
                tabHost.addTab(spec);

                intent = new Intent().setClass(MainTabActivity.this,
                        HealthAlertActivity.class);
                if (className.equals("browser")) {
                    intent.putExtra("className", "clinicalNot");
                } else {
                    intent.putExtra("className", "clinical");
                }

                spec = tabHost
                        .newTabSpec("health")
                        .setIndicator("",
                                res.getDrawable(R.drawable.health_alert_tab))
                        .setContent(intent);
                tabHost.addTab(spec);

                intent = new Intent().setClass(MainTabActivity.this,
                        CouponAlertActivity.class);
                spec = tabHost
                        .newTabSpec("coupon")
                        .setIndicator("",
                                res.getDrawable(R.drawable.coupon_alert_tab))
                        .setContent(intent);
                tabHost.addTab(spec);

                intent = new Intent().setClass(MainTabActivity.this,
                        SettingsActivity.class);

                String settingsCheck = mPreferences.getPreference("settingsCheck","");
                if (settingsCheck.equals("false")) {
                    spec = tabHost
                            .newTabSpec("settings")
                            .setIndicator(
                                    "",
                                    res.getDrawable(R.drawable.settings_notification_alert))
                            .setContent(intent);
                    tabHost.addTab(spec);
                } else {
                    spec = tabHost
                            .newTabSpec("settings")
                            .setIndicator("",
                                    res.getDrawable(R.drawable.settings_tab))
                            .setContent(intent);
                    tabHost.addTab(spec);

                }
                TabWidget tw = tabHost.getTabWidget();

                View v;
                for (int i = 0; i < tw.getChildCount(); i++) {
                    v = tw.getChildAt(i);
                    v.setTag("" + i);
                    v.setBackgroundDrawable(getResources().getDrawable(
                            R.drawable.bottom_bar));
                }

                if (new CheckNetwork().isNetAvailable(MainTabActivity.this)) {
                    new WebUrlHelper().execute();
                }

                if (new CheckNetwork().isNetAvailable(MainTabActivity.this)) {
                    pushNotification();
                }
                checkGeoLocation();
                if (className.equals("main")) {
                    tabHost.setCurrentTab(1);
                } else if (className.equals("browser")) {
                    tabHost.setCurrentTab(2);
                } else {
                    tabHost.setCurrentTab(0);
                }
                phoneCallHandler.run();
            } catch (Exception e) {
                Log.v(StringConstants.TAG_CALENDER_ALERT, e.toString());
            }

        }
@Override
    protected void onDestroy() {
        super.onDestroy();
        checkFlagFinish = false;
        HealthAssistDatabase had = HealthAssistDatabase.getDatabaseConn();
        if (had.isOpen())
            had.close();
        had = null;
        //mPreferences.savePreference("present", "false");
    }
@Override
    public void onBackPressed() {
        super.onBackPressed();
        this.finish();
        android.os.Process.killProcess(android.os.Process.myPid());
    }
    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

//  @Override
//  public void finish() {
//      super.finish();
//      
//  }
    public void showTimeoutPopup() {
        Log.v("in showTimeoutPopup", "in showTimeoutPopup");
        mPreferences.savePreference("timeout", "true");
        try {
            starttimeoutThread();
        } catch (Exception e) {
            e.printStackTrace();
        }

        new AlertDialog.Builder(context).setIcon(R.drawable.icon57_1)
        .setTitle("HealthCareAssist")
        .setMessage("Please click on OK otherwise your session will timeout in 10 seconds.")
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.dismiss();
                mPreferences.savePreference("timeout", "false");

            }
        }).setOnKeyListener(new DialogInterface.OnKeyListener() {

            @Override
            public boolean onKey(DialogInterface dialog,
                    int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_SEARCH
                        && event.getRepeatCount() == 0) {
                    return true; // Pretend we processed it
                }
                if (keyCode == KeyEvent.KEYCODE_MENU
                        && (event.getFlags() & KeyEvent.FLAG_LONG_PRESS) == KeyEvent.FLAG_LONG_PRESS) {
                    return true;
                }
                return false; // Any other keys are still
                // processed as normal
            }
        }).create().show();
    }
        protected void onPause() {
        super.onPause();
        Log.v("onpause", "onpause");
shotimeoup()
}

0 个答案:

没有答案