android upload photo to facebook illegal threadexception
in my app i give the user otion to share using action_send intent. during the upload to facebook my app crashes but the photo uploading succeeds. this is my code and the logcat. what do you suggest?
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.fromFile(file);
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
getContext().startActivity(Intent.createChooser(sharingIntent, "Share image using"));
Stacktrace:
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): FATAL EXCEPTION: main
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): java.lang.IllegalThreadStateException: Thread already started.
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at java.lang.Thread.start(Thread.java:1322)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at tomer.idunku3.GameView$1.surfaceCreated(GameView.java:103)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.view.SurfaceView.updateWindow(SurfaceView.java:532)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:206)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.view.View.dispatchWindowVisibilityChanged(View.java:3891)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java开发者_运维知识库:719)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:719)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:719)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.view.ViewRoot.performTraversals(ViewRoot.java:744)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.os.Looper.loop(Looper.java:123)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at java.lang.reflect.Method.invokeNative(Native Method)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at java.lang.reflect.Method.invoke(Method.java:521)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-01 23:06:59.649: ERROR/AndroidRuntime(7273): at dalvik.system.NativeStart.main(Native Method)
try:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
extracted from here
精彩评论