Android后台切回到应用显示广告页
2017-06-17 13:27
766 查看
看到市面上的很多app从后台切回到app会有广告页显示,因此也尝试了下,经过测试,以下的代码可以实现。
/** * Created by myc on 2017/6/17. * More Code on 1101255053@qq.com * Description: */ public class BaseActivity extends Activity { private static final String TAG = "BaseActivity"; //用来控制应用前后台切换的逻辑 private boolean isCurrentRunningForeground = true; @Override protected void onStart() { super.onStart(); if (!isCurrentRunningForeground) { isCurrentRunningForeground=true; //处理跳转到广告页逻辑 Intent intennt=new Intent(this,LoadingActivity.class); startActivity(intennt); Log.e(TAG, ">>>>>>>>>>>>>>>>>>>切回前台 activity process"); } } @Override protected void onStop() { super.onStop(); isCurrentRunningForeground = isRunningForeground(); if (!isCurrentRunningForeground) { Log.e(TAG,">>>>>>>>>>>>>>>>>>>切到后台 activity process"); } } public boolean isRunningForeground() { ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> appProcessInfos = activityManager.getRunningAppProcesses(); // 枚举进程,查看该应用是否在运行 for (ActivityManager.RunningAppProcessInfo appProcessInfo : appProcessInfos) { if (appProcessInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { if (appProcessInfo.processName.equals(this.getApplicationInfo().processName)) { Log.e(TAG,"EntryActivity isRunningForeGround"); return true; } } } Log.e(TAG, "EntryActivity isRunningBackGround"); return false; } }
相关文章推荐
- Android-应用内悬浮球(应用置于后台时不显示)
- Android判断应用是否是从后台回到前台
- Android 实现监听应用从后台回到前台
- android怎么判断程序在后台运行,让后将程序图标显示在状态栏
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)[转]
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动
- Android 应用程序窗体显示状态操作----requestWindowFeature()的应用
- Android深入浅出系列之实例应用—简单的手指拖动图片,图片滑来滑去显示应用Gallery和BaseAdapter以及ImageView的使用
- Android应用中在ImageView中显示SD卡上的图片
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
- Android 转:应用程序窗体显示状态操作(requestWindowFeature()的应用
- Android 应用启动时,显示加载画面后进入主画面(处理耗时的初始化)
- Android应用中在ImageView中显示SD卡上的图片
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用) [轉載]
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动