我只是尝试与我的应用程序的链接共享字符串。这是我的代码:
public static void shareApp(Activity activity){
ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder.from(activity);
builder.setText("some link")
.setType("text/html");
activity.startActivity(builder.createChooserIntent());
}
通常它工作得很好。但有时我在下一个堆栈跟踪时遇到错误:
0 java.lang.OutOfMemoryError: bitmap size exceeds VM budget
1 at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
2 at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
3 at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
4 at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
5 at android.content.res.Resources.loadDrawable(Resources.java:1709)
6 at android.content.res.Resources.getDrawable(Resources.java:581)
7 at android.app.ContextImpl$ApplicationPackageManager.getDrawable(ContextImpl.java:2201)
8 at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:140)
9 at android.content.pm.ComponentInfo.loadDefaultIcon(ComponentInfo.java:154)
10 at android.content.pm.PackageItemInfo.loadIcon(PackageItemInfo.java:145)
11 at android.content.pm.ResolveInfo.loadIcon(ResolveInfo.java:181)
12 at com.android.internal.app.ResolverActivity$ResolveListAdapter.bindView(ResolverActivity.java:431)
13 at com.android.internal.app.ResolverActivity$ResolveListAdapter.getView(ResolverActivity.java:415)
14 at android.widget.AbsListView.obtainView(AbsListView.java:1430)
15 at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
16 at android.widget.ListView.onMeasure(ListView.java:1127)
或与:
0 java.lang.OutOfMemoryError: bitmap size exceeds VM budget
1 at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
2 at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
3 at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
4 at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
5 at android.content.res.Resources.loadDrawable(Resources.java:1709)
6 at android.content.res.Resources.getDrawable(Resources.java:581)
7 at android.widget.AbsListView.setOverScrollMode(AbsListView.java:655)
8 at android.view.View.<init>(View.java:1879)
9 at android.view.View.<init>(View.java:1921)
10 at android.view.ViewGroup.<init>(ViewGroup.java:292)
11 at android.widget.AdapterView.<init>(AdapterView.java:228)
12 at android.widget.AbsListView.<init>(AbsListView.java:592)
13 at android.widget.ListView.<init>(ListView.java:163)
14 at android.widget.ListView.<init>(ListView.java:159)
15 at com.android.internal.app.AlertController$RecycleListView.<init>(AlertController.java:673)
这个错误是在 HTC Nexus One 上用 Android 2.3.6 重现的,我认为这个设备存在这个问题 - 它很旧而且速度很慢。但是我可以为方法或其他解决方法创建一些包装器startActivity()
来阻止这种崩溃吗?