为应用程序创建会话超时

时间:2012-12-07 07:51:43

标签: android

我的应用程序中有很多活动(例如A-> B-> C-> D)... A是登录活动...我有一个用于会话超时的倒数计时器。我想要做的是....注销用户..即如果活动B,C,D中没有用户交互,则将他放回活动A ...我已经扩展了我的应用程序类并实例化了我的计时器在那...但在这项活动中,我无法清除以前活动的堆栈,即行

addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

引发异常。任何想法我将如何解决这个问题......这是我的代码......

public class MyApp extends Application {

    MyCount count;

    @Override
    public void onCreate() {
        // reinitialize variable
        count = new MyCount(5000, 1000);
    }

    public void startcounter() {
        count.start();
    }

    public void cancelcounter() {
        count.cancel();
    }

    public class MyCount extends CountDownTimer {
        public MyCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onFinish() {
            try{
            Intent my = new Intent(getApplicationContext(), Login.class);
            my.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            startActivity(my);
            Toast.makeText(getApplicationContext(), "Finsihed",
                    Toast.LENGTH_LONG).show();
            }
            catch(Exception e )
            {
                Toast.makeText(getApplicationContext(), String.valueOf(e),
                        Toast.LENGTH_LONG).show();

            }
        }

        @Override
        public void onTick(long millisUntilFinished) {
            // TODO Auto-generated method stub
//          Toast.makeText(getApplicationContext(), String.valueOf(millisUntilFinished/1000),
    //              Toast.LENGTH_LONG).show();          
        }
    }
}

0 个答案:

没有答案