如何使用FirebaseInstanceId.getInstance().deleteInstanceId()?

我想删除我的 FireBaseInstance

FirebaseInstanceId.getInstance().deleteInstanceId() 

我使用尝试/捕获块,但我得到这个错误:

> W/System.err: java.io.IOException: MAIN_THREAD W/System.err:     at
> com.google.firebase.iid.zzd.zzb(Unknown Source) W/System.err:     at
> com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId(Unknown
> Source) W/System.err:     at
> package.class.onCreate(DatenLadenActivity.java:57)
> W/System.err:     at
> android.app.Activity.performCreate(Activity.java:6272) W/System.err:  
> at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
> W/System.err:     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
> W/System.err:     at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
> W/System.err:     at
> android.app.ActivityThread.access$900(ActivityThread.java:157)
> W/System.err:     at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
> W/System.err:     at
> android.os.Handler.dispatchMessage(Handler.java:102) W/System.err:    
> at android.os.Looper.loop(Looper.java:148) W/System.err:     at
> android.app.ActivityThread.main(ActivityThread.java:5525)
> W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
> W/System.err:     at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
> W/System.err:     at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)

感谢您的回答:)


答案 1

deleteInstanceId()是阻塞呼叫。它不能在主线程上调用。如果你只需要调用它进行开发和测试,你可以使用一个简单的:Thread

            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        FirebaseInstanceId.getInstance().deleteInstanceId();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }).start();

答案 2

推荐