0

我的应用程序中有很多活动(例如 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();          
        }
    }
}
4

0 回答 0