我的应用提供“分享/告诉朋友”功能。当按下“共享”按钮时,将调用以下方法打开可执行操作的应用程序列表(例如,Gmail,Twittroid,Facebook ......):
public void share() {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getText(R.string.menu_share_subject));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, getText(R.string.menu_share_body));
startActivity(Intent.createChooser(shareIntent, getText(R.string.menu_share_intent)));
}
共享功能基本上有效。但是当共享应用程序(Facebook,Twitter,...)试图返回我的应用程序时,会抛出一个强制关闭。
我猜我的应用在共享过程中会在后台关闭。至少这是调试器所说的。
有什么想法吗?
问题似乎是应用程序在后台关闭。此外,当我从我的应用程序打开浏览器时,尝试使用后退键返回到我的应用程序。关闭一个力量。这是Log Cat输出
04-13 22:28:42.003: ERROR/AndroidRuntime(18915): Uncaught handler: thread main exiting due to uncaught exception 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): java.lang.RuntimeException: Unable to start activity ComponentInfo{eu.xxx.xxx/eu.xxx.xxx.xxx}: java.lang.NullPointerException 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.ActivityThread.access$2100(ActivityThread.java:116) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.os.Handler.dispatchMessage(Handler.java:99) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.os.Looper.loop(Looper.java:123) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.ActivityThread.main(ActivityThread.java:4203) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at java.lang.reflect.Method.invokeNative(Native Method) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at java.lang.reflect.Method.invoke(Method.java:521) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at dalvik.system.NativeStart.main(Native Method) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): Caused by: java.lang.NullPointerException 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at eu.xxx.xxx.xxx.fillData(xxx.java:178) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at eu.xxx.xxx.xxx.access$1(xxx.java:173) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at eu.xxx.xxx.xxx$1.onTextChanged(xxx.java:139) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.widget.TextView.sendOnTextChanged(TextView.java:6096) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.widget.TextView.setText(TextView.java:2677) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.widget.TextView.setText(TextView.java:2542) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.widget.EditText.setText(EditText.java:71) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.widget.TextView.setText(TextView.java:2517) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.widget.TextView.onRestoreInstanceState(TextView.java:2417) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.view.View.dispatchRestoreInstanceState(View.java:5689) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1125) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1125) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1125) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.view.View.restoreHierarchyState(View.java:5668) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1506) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.Activity.onRestoreInstanceState(Activity.java:833) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.ListActivity.onRestoreInstanceState(ListActivity.java:221) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.Activity.performRestoreInstanceState(Activity.java:805) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1172) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2378) 04-13 22:28:42.253: ERROR/AndroidRuntime(18915): ... 11 more
答案 0 :(得分:4)
04-13 22:28:42.253: ERROR/AndroidRuntime(18915): Caused by: java.lang.NullPointerException
04-13 22:28:42.253: ERROR/AndroidRuntime(18915): at xx.xxx.xxx.xxx.fillData(xxx.java:178)
你有NullPointerException
。解决这个问题,幸运的是,你的问题将会消失。
答案 1 :(得分:0)
public void share() {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, new String(getText(R.string.menu_share_subject)));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, new String(getText(R.string.menu_share_body)));
startActivity(Intent.createChooser(shareIntent, getText(R.string.menu_share_intent)));
}
做的工作:) 不知道为什么其他地方它确实有效,但是通过这个添加,它按预期工作:) 还要感谢您的回复