顯示具有 Exception 標籤的文章。 顯示所有文章
顯示具有 Exception 標籤的文章。 顯示所有文章

2017年6月7日 星期三

Crash when set TYPE_DISPLAY_OVERLAY type by inflection

Error:
android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@71dc214 -- permission denied for window type 2026

Solution:
TYPE_DISPLAY_OVERLAY需要
android.Manifest.permission.INTERNAL_SYSTEM_WINDOW

AndroidManifest.xml
<permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" android:protectionLevel="signature" />

app要 sign platform key才可使用


Call stack:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hueijheyu.reflectiondemo/com.example.hueijheyu.reflectiondemo.MainActivity}: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@71dc214 -- permission denied for window type 2026
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:154)
                                                       at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                    Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@71dc214 -- permission denied for window type 2026
                                                       at android.view.ViewRootImpl.setView(ViewRootImpl.java:703)
                                                       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
                                                       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
                                                       at android.app.Dialog.show(Dialog.java:322)
                                                       at com.example.hueijheyu.reflectiondemo.MainActivity.onCreate(MainActivity.java:39)
                                                       at android.app.Activity.performCreate(Activity.java:6723)
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:154)
                                                       at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

2016年3月6日 星期日

IllegalArgumentException: View not attached to window manager

Reference:

http://stackoverflow.com/questions/22924825/view-not-attached-to-window-manager-crash
http://www.2cto.com/kf/201202/119310.html

Scenario:

UI thread產生另一個 thread(Ex: AsyncTask)來顯示一個 Dialog,當 thread任務完成了再 dismiss dialog,如果在此期間 Activity因為某種原因被殺掉且又重新啟動了,那麼當  Dismiss的時候, WindowManager檢查發現  Dialog所屬的  Activity已經不存在了,就會跳出這個 Exception

Code snippet:

@Override
protected void onDestroy() {
    dismissProgressDialog();
    super.onDestroy();
}

protected void onPostExecute(String file_url)
{
    if (YourActivity.this.isDestroyed()) { // or call isFinishing() if min sdk version < 17
        return;
    }
    dismissProgressDialog();
    something(note);
}

private void dismissProgressDialog() {
    if (mDialog != null && mDialog.isShowing()) {
        mDialog.dismiss();
    }
}


2016年1月11日 星期一

[Exception] couldn't find class 'com.google.android.gms.measurement.internal.zzz'

References:

http://stackoverflow.com/questions/33196015/error-on-some-devices-couldnt-find-class-com-google-android-gms-measurement

Error log:

01-12 14:45:58.910    4347-4347/? E/dalvikvm﹕ Could not find class 'com.google.android.gms.measurement.internal.zzx', referenced from method com.google.android.gms.measurement.internal.zzt.zzaU

    java.lang.VerifyError: com/google/android/gms/measurement/internal/zzt
            at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source)
            at android.content.ContentProvider.attachInfo(ContentProvider.java:1591)
            at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)
            at android.app.ActivityThread.installProvider(ActivityThread.java:4897)
            at android.app.ActivityThread.installContentProviders(ActivityThread.java:4487)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4427)
            at android.app.ActivityThread.access$1500(ActivityThread.java:143)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1302)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5124)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613)
            at dalvik.system.NativeStart.main(Native Method)

Code snippet:

MyApplication.java
public class MyApplication extends Application {

    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

AndroidManifest.xml
<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/xxxxxx"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

Solution:

This happens because of multi-dexing. When your code is so big that it can't be compiled with a single dex file, we use multidexing. But after that it wouldn't run on all phones

2015年11月25日 星期三

[Exception] The specified child already has a parent. You must call removeView() on the child's parent first.

Reference:
http://www.cnblogs.com/over140/archive/2013/06/06/3121354.html

Pre-condition:
Activity + Fragment

Solution:
View v = inflater.inflate(R.layout.preference_fragment, container, false);