Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何找到任务最重要的活动?_Android - Fatal编程技术网

Android 如何找到任务最重要的活动?

Android 如何找到任务最重要的活动?,android,Android,我有一个应用程序,在后台运行计时器事件,检查是否处于非活动状态。当一段时间过去后,我想为我的应用程序(任务)当前最重要的活动调用finish()方法。请注意,我的应用程序可以位于后台,因此我不能仅使用设备上最活跃的活动。我的问题是,为我的任务找到最上面的活动,然后为该活动调用finish()方法。下面是我正在使用的可运行计时器的一个片段。我的代码片段中的“activity”变量似乎是我找不到的 mUpdateTimeTask = new Runnable() { public void r

我有一个应用程序,在后台运行计时器事件,检查是否处于非活动状态。当一段时间过去后,我想为我的应用程序(任务)当前最重要的活动调用finish()方法。请注意,我的应用程序可以位于后台,因此我不能仅使用设备上最活跃的活动。我的问题是,为我的任务找到最上面的活动,然后为该活动调用finish()方法。下面是我正在使用的可运行计时器的一个片段。我的代码片段中的“activity”变量似乎是我找不到的

mUpdateTimeTask = new Runnable() 
{
  public void run() 
  {
     // - for every 10 seconds, this runnable task will check the inactivity time and will exit this app
     //   if the time allocated is exceeded

     long longNowTime = System.currentTimeMillis()/1000;

     if ( longNowTime-globalVariables.longLastActivityTime >= globalVariables.intLockoutDuration )
     {                 
         // - first, we'll stop the lockout timer from running

         mHandler.removeCallbacks(mUpdateTimeTask);

         // - call the finish() method to close the top most activity for this task (app)

         activity.finish();
     }

     mHandler.postDelayed(this,mIntInterval);
  }
};
有谁能给我一些建议,告诉我如何为我最重要的活动获取活动对象并调用finish()方法来关闭它


谢谢。

使用常用的onPause和onResume方法将所有活动子类设置为一个公共超类,这些方法维护一个“TopmostActivity”变量,可能作为超类的一个静态字段