android annotations @background NetworkOnMainThrea

2019-08-11 09:55发布

Why I get this error? Shouldn't android annotations take care of threading? Any help will be appreciated :). Thank you

@EActivity(R.layout.activity_main)
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        tradingHistory();

    }
    void myMethod() {
        tradingHistory();
    }
    @Background
    void tradingHistory (){
        Helper helper = new Helper();
        try {

            helper.TradeHistory tradeHistory = helper.getTradeHistory();
            System.out.println(tradeHistory.toString());
        } catch (Helper.HelperException e) {
            e.printStackTrace();
        }
    }



}

2条回答
神经病院院长
2楼-- · 2019-08-11 10:09

You probably use wrong Activity in your Manifest - You should use MainActivity_ instead of MainActivity

查看更多
迷人小祖宗
3楼-- · 2019-08-11 10:21

if you're just doing some development you can turn it off using:

import android.os.StrictMode;

StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder()
.permitAll().build(); 
StrictMode.setThreadPolicy(policy);

but I'd recommend to dug into Android AsyncTask some more.

查看更多
登录 后发表回答