我希望在这里找到一些帮助,因为我不熟悉Android中的broadcastReceivers.这段代码打开WebVIEw会将您重定向到登录页面,并在检测到URL更改后接收登录令牌.之后,活动将关闭.
@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_login); mLoginWebVIEw = (WebVIEw) findVIEwByID(R.ID.webvIEw_login); redirectUrl = getString(R.string.app_redirect_url); //RECEIVE PLATFORM ID Bundle bundle = getIntent().getExtras(); if(bundle != null){ platform = bundle.getInt(ConstantsHelper.LOGIN_EXTRA_TOKEN); } mLoginWebVIEw.setWebVIEwClIEnt(new WebVIEwClIEnt() { @OverrIDe public boolean shouldOverrIDeUrlLoading(WebVIEw vIEw, String url) { Log.d(TAG, "URL change to to " + url + " was detected"); if (url.contains(redirectUrl) || url.contains("passport.twitch.tv")) { Log.d(TAG, "Login with platform " + platform); switch (platform){ //GET INSTAGRAM AUTH TOKEN case ConstantsHelper.ID_INSTAGRAM:{ String accesstoken = url.split("=")[1]; SharedPreferenceHelper.putString(ConstantsHelper.PREF_INST_ACCESS_TOKEN, accesstoken); NetworkManager.getInstance().catchTokens(); } //GET TWITCH AUTH TOKEN case ConstantsHelper.ID_TWITCH:{ String accesstoken = url.substring(url.indexOf("=") + 1, url.indexOf("&")); SharedPreferenceHelper.putString(ConstantsHelper.PREF_TWITCH_ACCESS_TOKEN, accesstoken); NetworkManager.getInstance().catchTokens(); } } finish(); //Activity is closed return true; } return false; } }); switch (platform){ case 1: mLoginWebVIEw.loadUrl(NetworkManager.getInstance().getInstagramAuthUrl(getApplicationContext())); case 4: mLoginWebVIEw.loadUrl(NetworkManager.getInstance().getTwitchAuthUrl(getApplicationContext())); }}
没有任何反应,LogCat显示此错误:
Activity com.maximutan.socialmedia_Feed_merger.activitIEs.LoginActivity has leaked IntentReceiver org.chromium.content.browser.accessibility.LollipopbrowserAccessibilityManager@25014a that was originally registered here. Are you missing a call to unregisterReceiver()?androID.app.IntentReceiverLeaked: Activity com.maximutan.socialmedia_Feed_merger.activitIEs.LoginActivity has leaked IntentReceiver org.chromium.content.browser.accessibility.LollipopbrowserAccessibilityManager@25014a that was originally registered here. Are you missing a call to unregisterReceiver()?at androID.app.LoadedApk$Receiverdispatcher.<init>(LoadedApk.java:962)at androID.app.LoadedApk.getReceiverdispatcher(LoadedApk.java:763)at androID.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1179)at androID.app.ContextImpl.registerReceiver(ContextImpl.java:1159)at androID.app.ContextImpl.registerReceiver(ContextImpl.java:1153)at androID.content.Contextwrapper.registerReceiver(Contextwrapper.java:554)at androID.content.Contextwrapper.registerReceiver(Contextwrapper.java:554)at org.chromium.content.browser.accessibility.LollipopbrowserAccessibilityManager.<init>(LollipopbrowserAccessibilityManager.java:3)at org.chromium.content.browser.accessibility.browserAccessibilityManager.create(browserAccessibilityManager.java:2)at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:7) at androID.os.Handler.dispatchMessage(Handler.java:102)at androID.os.Looper.loop(Looper.java:148)at androID.app.ActivityThread.main(ActivityThread.java:5527),at java.lang.reflect.Method.invoke(Native Method)at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:620)
我的问题是我不知道我必须取消注册哪个broadcastReceiver,因为我没有创建和初始化它.
谢谢你的帮助
解决方法:
当WebVIEw仍附加到其父视图时,在WebVIEw上调用destroy()时会发生此问题.
可以通过在调用destroy()之前首先从其父视图中删除WebvIEw来解决崩溃.
请注意,即使您没有手动调用destroy()(就像我的情况一样),这种崩溃仍然可能发生.我发现关键是你必须明确销毁一个WebVIEw(至少在一个片段中),因为AndroID不会为你处理这个问题,在这之前你必须从它的父视图中删除它.
例如,如果您有WebVIEw片段:
@OverrIDe public voID onDestroyVIEw() { super.onDestroyVIEw(); // destroy the WebVIEw completely if (mWebVIEw != null) { // the WebVIEw must be removed from the vIEw hIErarchy before calling destroy // to prevent a memory leak // See https://developer.androID.com/reference/androID/webkit/WebVIEw.HTML#destroy%28%29 ((VIEwGroup) mWebVIEw.getParent()).removeVIEw(mWebVIEw); mWebVIEw.removeAllVIEws(); mWebVIEw.destroy(); mWebVIEw = null; } }
完全归功于Billy Brawner:https://brawner.tech/2017/12/03/webview-memory-leak/
总结以上是内存溢出为你收集整理的java – Activity泄露了IntentReceiver – LollipopBrowserAccessibilityManager全部内容,希望文章能够帮你解决java – Activity泄露了IntentReceiver – LollipopBrowserAccessibilityManager所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)