我正在恢复设备上安装的所有应用程序,我偶然发现了这个错误。
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:811)
Caused by: java.lang.RuntimeException: Package manager has died
at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:499)
at android.app.ApplicationPackageManager.queryIntentActivities(ApplicationPackageManager.java:485)
at com.name.package.MyClass$RetrieveApps.doInBackground(MyClass.java:363)
at com.name.package.MyClass$RetrieveApps.doInBackground(MyClass.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 4 more
Caused by: android.os.TransactionTooLargeException
at android.os.BinderProxy.transact(Native Method)
at android.content.pm.IPackageManager$Stub$Proxy.queryIntentActivities(IPackageManager.java:2165)
at android.app.ApplicationPackageManager.queryIntentActivitiesAsUser(ApplicationPackageManager.java:493)
... 9 more
在doInBackground()方法中,我使用此代码检索已安装的应用程序。
PackageManager packageManager = getPackageManager();
List<ResolveInfo> mResolveInfo;
Intent queryIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
mResolveInfo = packageManager.queryIntentActivities(queryIntent, 0);
for (ResolveInfo ri : resolveInfos) {
Class class = new Class();
class.icon = ri.loadIcon(packageManager);
class.label = ri.loadLabel(packageManager);
class.packagename = ri.activityInfo.packageName;
class.packageclass = ri.activityInfo.name;
class.componentName = new ComponentName(class.packagename, class.packageclass);
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.setComponent(ai.componentName);
class.intent = i;
myArrayList.add(class);
发生崩溃的行是:
mResolveInfo = packageManager.queryIntentActivities(queryIntent, 0);
读取堆栈溢出我明白这可能是因为您安装了许多应用程序。现在的问题是,你怎么解决?有什么解决方案吗?如果是的话,哪一个?感谢。
答案 0 :(得分:3)
我正在寻找相同的解决方案。有没有办法对已安装的应用程序进行部分列表?
我的应用程序中存在同样的问题。
List<PackageInfo> packs = pm.getInstalledPackages(0);
如果用户拥有大量应用程序,我会在logcat中获得:
引起:java.lang.RuntimeException:包管理器已经死亡 在android.app.ApplicationPackageManager.getInstalledPackages(ApplicationPackageManager.java:424)
引起:android.os.TransactionTooLargeException 在android.os.BinderProxy.transact(本机方法) 在android.content.pm.IPackageManager $ Stub $ Proxy.getInstalledPackages(IPackageManager.java:2363)
更新!
我能找到一种方法。看到我在另一篇文章中给出的答案: