我的片段里面有一个Activity。在某些设备上,如小米应用程序崩溃和BOOL AddNotificationIcon(HWND hwnd)
{
NOTIFYICONDATA nid = {sizeof(nid)};
nid.hWnd = hwnd;
// add the icon, setting the icon, tooltip, and callback message.
// the icon will be identified with the GUID
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE | NIF_SHOWTIP | NIF_GUID;
nid.guidItem = __uuidof(PrinterIcon);
nid.uCallbackMessage = WMAPP_NOTIFYCALLBACK;
LoadIconMetric(g_hInst, MAKEINTRESOURCE(IDI_NOTIFICATIONICON), LIM_SMALL, &nid.hIcon);
LoadString(g_hInst, IDS_TOOLTIP, nid.szTip, ARRAYSIZE(nid.szTip));
Shell_NotifyIcon( NIM_ADD, &nid );
// NOTIFYICON_VERSION_4 is prefered
nid.uVersion = NOTIFYICON_VERSION_4;
return Shell_NotifyIcon(NIM_SETVERSION, &nid);
}
抛出。有堆栈跟踪:
OutOfMemoryError
Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 9437196 byte allocation with 5089232 free bytes and 4MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:613)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:446)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.createFromResourceStream(Resources.java:2937)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2669)
at android.content.res.Resources.loadDrawable(Resources.java:2569)
at android.content.res.TypedArray.getDrawable(TypedArray.java:872)
at android.widget.ImageView.<init>(ImageView.java:152)
at android.widget.ImageView.<init>(ImageView.java:140)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:57)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:963)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1022)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:839)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at com.rcd.perfecto.ui.fragments.AuthFragment.onCreateView(AuthFragment.java:154)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1988)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1250)
at android.support.v4.app.FragmentManagerImpl.dispatchReallyStop(FragmentManager.java:2148)
at android.support.v4.app.FragmentController.dispatchReallyStop(FragmentController.java:247)
at android.support.v4.app.FragmentActivity.onReallyStop(FragmentActivity.java:804)
at android.support.v4.app.FragmentActivity.doReallyStop(FragmentActivity.java:790)
at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:367)
at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:181)
at android.app.Activity.performDestroy(Activity.java:6474)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1143)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3823)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3854)
at android.app.ActivityThread.access$1500(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1403)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5432)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:735)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
调用onCreateView
方法时抛出异常。有方法:
AuthFragment
在行@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_auth, container, false);
ButterKnife.bind(this, view);
return view;
}
上抛出异常我该怎么做才能解决这个问题?
答案 0 :(得分:3)
您可以在应用程序中使用largeHeap。只需添加到Manifest:
<application
...
android:largeHeap="true"
...