View
1.038
Download
0
Category
Preview:
Citation preview
Foreground検知
About me
@kiharekato
Androidエンジニア
Tokyo Otaku Mode Inc.
Activity の Lifecycle にあるだろう
無い。
Applicationにあるんでしょ?
やっぱり無い。
まさか、Task系 !?
/**
* Return a list of the tasks that are currently running, with
** 中略 **
* <p><b>Note: this method is only intended for debugging and presenting
* task management user interfaces</b>. This should never be used for
* core logic in an application, such as deciding between different
* behaviors based on the information found here. Such uses are
* <em>not</em> supported, and will likely break in the future. For
* example, if multiple applications can be actively running at the
* same time, assumptions made about the meaning of the data here for
* purposes of control flow will be incorrect.</p>
*
* @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
* is no longer available to third party
* applications: the introduction of document-centric recents means
* it can leak person information to the caller. For backwards compatibility,
* it will still retu rn a small subset of its data: at least the caller's
* own tasks, and possibly some other tasks
* such as home that are known to not be sensitive.
*/
@Deprecated
public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException {
// 中略
}
ActivityManager.getRunningTasks
/**
* Return a list of the tasks that are currently running, with
** 中略 **
* <p><b>Note: this method is only intended for debugging and presenting
* task management user interfaces</b>. This should never be used for
* core logic in an application, such as deciding between different
* behaviors based on the information found here. Such uses are
* <em>not</em> supported, and will likely break in the future. For
* example, if multiple applications can be actively running at the
* same time, assumptions made about the meaning of the data here for
* purposes of control flow will be incorrect.</p>
*
* @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
* is no longer available to third party
* applications: the introduction of document-centric recents means
* it can leak person information to the caller. For backwards compatibility,
* it will still retu rn a small subset of its data: at least the caller's
* own tasks, and possibly some other tasks
* such as home that are known to not be sensitive.
*/
@Deprecated
public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException {
// 中略
}
ActivityManager.getRunningTasks
!?
/**
* Return a list of the tasks that are currently running, with
** 中略 **
* <p><b>Note: this method is only intended for debugging and presenting
* task management user interfaces</b>. This should never be used for
* core logic in an application, such as deciding between different
* behaviors based on the information found here. Such uses are
* <em>not</em> supported, and will likely break in the future. For
* example, if multiple applications can be actively running at the
* same time, assumptions made about the meaning of the data here for
* purposes of control flow will be incorrect.</p>
*
* @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method
* is no longer available to third party
* applications: the introduction of document-centric recents means
* it can leak person information to the caller. For backwards compatibility,
* it will still retu rn a small subset of its data: at least the caller's
* own tasks, and possibly some other tasks
* such as home that are known to not be sensitive.
*/
@Deprecated
public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException {
// 中略
}
ActivityManager.getRunningTasks
!?
!?
Androidでは、
SDK側で提供されて無いじゃね?
public class MyApplication extends Application {
private Timer mActivityTransitionTimer;
private TimerTask mActivityTransitionTimerTask;
public boolean wasInBackground;
private final long MAX_ACTIVITY_TRANSITION_TIME_MS = 2000;
// これをonResumeで実行
public void startActivityTransitionTimer() {
this.mActivityTransitionTimer = new Timer();
this.mActivityTransitionTimerTask = new TimerTask() {
public void run() {
MyApplication.this.wasInBackground = true;
}
};
this.mActivityTransitionTimer.schedule(mActivityTransitionTimerTask, MAX_ACTIVITY_TRANSITION_TIME_MS);
}
// これをonPauseで実行
public void stopActivityTransitionTimer() {
if (this.mActivityTransitionTimerTask != null) this.mActivityTransitionTimerTask.cancel();
if (this.mActivityTransitionTimer != null) this.mActivityTransitionTimer.cancel();
this.wasInBackground = false;
}
}
http://stackoverflow.com/a/15573121
うーん。微妙じゃね?
Application.ActivityLifecycleCallbacks
Application.ActivityLifecycleCallbacks
UsageStatsManager.queryEvents
UsageStatsManager.queryEvents
簡単に行えないのか?
画面の構成をFragmentに移すことによって、
ActivityをApplicationと同等の完全単一にすることに
よって、Activity.onResumeでForegroundを取得
できるという計画である。
Activity補完計画
他に良い方法をご存知でしたら、教えてください。
ありがとうございました。
Recommended