yedawei007 / android-weibo-sdk

Automatically exported from code.google.com/p/android-weibo-sdk
0 stars 0 forks source link

Android Throws NetworkOnMainThreadException on share2weibo Call #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set Android SDK to 11
2. Implement Weibo authorize and share2weibo
3. Android crashes on Utility.openUrl call, citing NetworkOnMainThreadException

What is the expected output? What do you see instead?
Expect to share the message on Weibo successfully, but it threw the exception 
mentioned above

What version of the product are you using? On what operating system?
Android 3.2 (Honeycomb), Android 4.0.2 (Ice Cream Sandwich)

Please provide any additional information below.
Since Android SDK 11, Android requires the network access to run on a separate 
thread from the UI. This is to ensure the UI is responsive during the network 
access. Since the operation is mandatory for SDK 11, changes are needed to make 
sure it work.
Perhaps the weibo-sdk library shall implement async operation for the 
share2weibo call.

Original issue reported on code.google.com by jackche...@cloudpillar.com.hk on 21 May 2012 at 9:00

GoogleCodeExporter commented 9 years ago
I've figure out the issue of crashing. It is a bug in AsyncWeiboRunner class.
How should I submit bugfix / commit to the code?

Original comment by jackche...@cloudpillar.com.hk on 29 May 2012 at 1:22

GoogleCodeExporter commented 9 years ago
AsyncWeiboRunner的大概第52行:
new Thread(){
            @Override public void run() {
                try {
                    String resp = mWeibo.request(context, url, params, httpMethod, mWeibo.getAccessToken());
                    listener.onComplete(resp);
                } catch (WeiboException e) {
                    listener.onError(e);
                }
            }
        }.run();
.run()改成.start();

貌似是个低级错误哦。

Original comment by yaoxing...@gmail.com on 13 Sep 2012 at 2:42