0

嗨,我正在使用整个应用程序中的选项卡为应用程序工作。在该特定选项卡中集成了 facebook 和 twitter.its 单击 facebook 按钮后,它显示 facebook 的登录屏幕和登录成功也可以正常工作,但是登录完成后我想重定向到另一个活动,我在 onComplete() 中使用了以下代码

                   View view = Socialtab.group.getLocalActivityManager()  
                       .startActivity("Items", new Intent(Social.this,MainActivity.class)
                       .putExtra("name", name)
                       .putExtra("email", email)
                       .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))  
                       .getDecorView();
                    Socialtab.group.replaceView(view); 

它在以下行显示异常

.startActivity("Items", new Intent(Social.this,MainActivity.class)

我的logcat错误如下:

    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.karmakexpo/com.karmakexpo.MainActivity}: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1618)   
at android.app.ActivityThread.startActivityNow(ActivityThread.java:1524)

at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)

at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)    
at com.karmakexpo.Social.jsonParsing(Social.java:353)   
at com.karmakexpo.Social$SampleRequestListener.onComplete(Social.java:258)  
at com.karmakexpo.facebook.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:238)

Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

at android.os.Handler.<init>(Handler.java:121)
at android.app.Activity.<init>(Activity.java:698)

at com.karmakexpo.MainActivity.<init>(MainActivity.java:56)

at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1409) at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1610)
... 6 more

我用谷歌搜索并没有得到任何解决方案请提供解决方案提前谢谢..

4

2 回答 2

0

尝试使用 runOnUiThread :

  Social.this.runOnUiThread(new Runnable() {

    @Override
    public void run() {
     // TODO Auto-generated method stub
                    View view = Socialtab.group.getLocalActivityManager()  
               .startActivity("Items", new Intent(Social.this,MainActivity.class)
               .putExtra("name", name)
               .putExtra("email", email)
               .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))  
               .getDecorView();
               Socialtab.group.replaceView(view); 
    }
   });
于 2012-10-13T10:48:08.240 回答
0

您需要在主 UI 线程中运行代码。

试试这个

Looper.prepare();  // Initialize the current thread as a looper. This gives you a chance to create handlers that then reference this looper, before actually starting the loop. 

 View view = Socialtab.group.getLocalActivityManager()  
               .startActivity("Items", new Intent(Social.this,MainActivity.class)
               .putExtra("name", name)
               .putExtra("email", email)
               .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))  
               .getDecorView();
               Socialtab.group.replaceView(view); 
Looper.loop();
于 2012-10-13T10:55:25.533 回答