1

在我的应用程序中,我使用 SharCompat 来获取我想要共享内容的应用程序列表。我在列表中有 twitter 应用程序。当我在设备中访问 twitter 应用程序时。我遇到了以下异常。

要打开应用程序列表以共享内容,我使用了以下代码

ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder.from(Myactivity.this);
builder.setType("text/plain");
Intent i = builder.getIntent();
startActivity(Intent.createChooser(i, "test"));

打开 Twitter 应用程序的签名页面时出现以下异常

06-20 02:10:49.205: E/AndroidRuntime(15402): java.lang.RuntimeException: Unable to destroy activity {com.twitter.android/com.twitter.android.PostActivity}: java.lang.NullPointerException
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3112)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3130)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.app.ActivityThread.access$1200(ActivityThread.java:123)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1180)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.os.Looper.loop(Looper.java:137)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.app.ActivityThread.main(ActivityThread.java:4424)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at java.lang.reflect.Method.invokeNative(Native Method)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at java.lang.reflect.Method.invoke(Method.java:511)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at dalvik.system.NativeStart.main(Native Method)
06-20 02:10:49.205: E/AndroidRuntime(15402): Caused by: java.lang.NullPointerException
06-20 02:10:49.205: E/AndroidRuntime(15402):    at com.twitter.android.PostActivity.onDestroy(Twttr:739)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.app.Activity.performDestroy(Activity.java:4656)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1079)
06-20 02:10:49.205: E/AndroidRuntime(15402):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3099)

请帮助如何解决这个 pbm 。谢谢

4

1 回答 1

1

这段代码对我有用:

Intent shareIntent = ShareCompat.IntentBuilder
                .from(LocalCharadeActivity.this).setType("text/plain")
                .setText("lalal").getIntent();

startActivity(shareIntent);
于 2013-12-14T19:45:52.870 回答