本文目录
- activityManager是什么它具体有什么作用
- PackageManager和ActivityManager的区别是什么
- android怎样判断应用程序退到后台
- 如何初始化activitymanager
- android系统activitymanager-launch是什么进程
- android 怎么修改activitymanagerservice.java
activityManager是什么它具体有什么作用
这问题,一百度一大堆吧。。。讲的都很详细的。。。
http://blog.csdn.net/caowenbin/article/details/6036726
http://blog.sina.com.cn/s/blog_8984d3f301011peb.html
PackageManager和ActivityManager的区别是什么
packagemanager是手机上所有安装软件的管理者,activitymanager是应用的activity的管理者,两者差的十万八千里吧,作用完全不同.
android怎样判断应用程序退到后台
/**
* 程序是否在前台运行
*
*/
public boolean isAppOnForeground() {
ActivityManager activityManager = (ActivityManager) getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
String packageName = getApplicationContext().getPackageName();
/**
* 获取Android设备中所有正在运行的App
*/
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;
}
这是我在网上找到的例子,主要的实现原理就是,使用ActivityManager,首先拿到自己App的包名,再拿到Android设备中所有正在运行的App包名,然后对所有的App进行遍历,通过判断正在运行的App中包名有没有和自己的App相等,从而判断自己的App是否退到后台.
@Override
protected void onPause() {
super.onPause();
if(!isAppOnForeground()){
Toast.makeText(getApplicationContext(), TAG+“onPause:“,
Toast.LENGTH_SHORT).show();
}else {
sendBroadcast(new Intent(NotificationIntentReceiver.ACTION_ENABLE_MESSAGES)
.setClass(this, NotificationIntentReceiver.class));
Toast.makeText(getApplicationContext(), TAG+“后台运行1“,
Toast.LENGTH_SHORT).show();
}
}
然后在onPause()方法中,进行判断,上面代码中实现的是,App退出后台就发送广播,然后在广播中执行Notification,然后在回到Activity时,在onResume()中清除应该清除Notification.
-activity
如何初始化activitymanager
在AndroidManifest.xml里修改 CdBusSearchActivity是主界面,如果想换成BusInfoActivity的话,只需交换两个的名字就行
android系统activitymanager-launch是什么进程
通过ActivityManager我们可以获得系统里正在运行的activities,包括
进程(Process)等、应用程序/包、服务(Service)、任务(Task)信息。
android 怎么修改activitymanagerservice.java
1 个文件发生了变化
android/frameworks/base/services/java/com/android/server/am/ActivityManagerService.java
android/frameworks/base/services/java/com/android/server/am/ActivityManagerService.java查看文件 @a1b2236
@@ -889,6 +889,8 @@
return;
}
AppErrorResult res = (AppErrorResult) data.get(“result“);
+ res.set(0);
+ /*
if (!mSleeping && !mShuttingDown) {
Dialog d = new AppErrorDialog(mContext, res, proc);
d.show();
@@ -897,7 +899,7 @@
// The device is asleep, so just pretend that the user
// saw a crash dialog and hit “force quit“.
res.set(0);
- }
+ }*/
}
ensureBootCompleted();
@@ -3193,6 +3195,11 @@
return;
}
+ app.notResponding = false;
+ app.notRespondingReport = null;
+ app.anrDialog = null;
+
+ /*
// Set the app’s notResponding state, and look up the errorReportReceiver
makeAppNotRespondingLocked(app,
activity != null ? activity.shortComponentName : null,
@@ -3210,6 +3217,7 @@
}
mHandler.sendMessage(msg);
+ */
}
}
android/frameworks/base/services/java/com/android/server/am/ActivityManagerService.java查看文件 @a1b2236
@@ -889,6 +889,8 @@
return;
}
AppErrorResult res = (AppErrorResult) data.get(“result“);
+ res.set(0);
+ /*
if (!mSleeping && !mShuttingDown) {
Dialog d = new AppErrorDialog(mContext, res, proc);
d.show();
@@ -897,7 +899,7 @@
// The device is asleep, so just pretend that the user
// saw a crash dialog and hit “force quit“.
res.set(0);
- }
+ }*/
}
ensureBootCompleted();
@@ -3193,6 +3195,11 @@
return;
}
+ app.notResponding = false;
+ app.notRespondingReport = null;
+ app.anrDialog = null;
+
+ /*
// Set the app’s notResponding state, and look up the errorReportReceiver
makeAppNotRespondingLocked(app,
activity != null ? activity.shortComponentName : null,
@@ -3210,6 +3217,7 @@
}
mHandler.sendMessage(msg);
+ */
}
}
-c