Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Foreground検知

1.386 Aufrufe

Veröffentlicht am

potatotips #26

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

Foreground検知

  1. 1. Foreground検知
  2. 2. About me @kiharekato Androidエンジニア Tokyo Otaku Mode Inc.
  3. 3. Activity の Lifecycle にあるだろう
  4. 4. 無い。
  5. 5. Applicationにあるんでしょ?
  6. 6. やっぱり無い。
  7. 7. まさか、Task系 !?
  8. 8. /** * 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
  9. 9. /** * 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 !?
  10. 10. /** * 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 !? !?
  11. 11. Androidでは、 SDK側で提供されて無いじゃね?
  12. 12. 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
  13. 13. うーん。微妙じゃね?
  14. 14. Application.ActivityLifecycleCallbacks
  15. 15. Application.ActivityLifecycleCallbacks
  16. 16. UsageStatsManager.queryEvents
  17. 17. UsageStatsManager.queryEvents
  18. 18. 簡単に行えないのか?
  19. 19.  画面の構成をFragmentに移すことによって、 ActivityをApplicationと同等の完全単一にすることに よって、Activity.onResumeでForegroundを取得 できるという計画である。 Activity補完計画
  20. 20. 他に良い方法をご存知でしたら、教えてください。 ありがとうございました。

×