編輯:關於Android編程
@Override protected void onStop() { if (!isAppOnForeground()) { Debug.i("dwy", "enter background"); mIsBackground = true; } else { Debug.i("dwy", "foreground"); mIsBackground = false; }
Judge is App in background when onStop() get called.
public boolean isAppOnForeground() { // Returns a list of application processes that are running on the // device ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE); String packageName = getApplicationContext().getPackageName(); List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager .getRunningAppProcesses(); if (appProcesses == null) return false; for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { // The name of the process that this object is associated with. if (appProcess.processName.equals(packageName) && appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { return true; } } return false; }
方法二:
/** * 需要權限:android.permission.GET_TASKS * * @param context * @return */ public boolean isApplicationBroughtToBackground(Context context) { ActivityManager am = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (tasks != null && !tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; Debug.i(TAG, "topActivity:" + topActivity.flattenToString()); Debug.f(TAG, "topActivity:" + topActivity.flattenToString()); if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; } } return false; }
之前的博文中有介紹關於圖片輪播的實現方式,分別為(含超鏈接):1、《Android中使用ViewFlipper實現屏幕切換》2、《Android中使用ViewPager實
最近公司要把百度地圖集成的項目中,於是我就研究了一天百度地圖的SDK,當前的版本:Android SDK v3.0.0 。 雖然百度地圖網上相關代碼比較多,
android_apk的在線安裝,除了要設計Android 客戶端的代碼外,還要搭建服務器的代碼,仿真實現中Android軟件的在線升級。 Android 客
vivo X9作為此前X7的升級版,外觀變化不大,主要變化在於背面天線變了,采用類似魅族MX6/iPhone7類似的弧線天線設計,背面金屬屏占比更高,外觀顯