问题
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();
}
}
}
回答1:
You probably use wrong Activity in your Manifest - You should use MainActivity_
instead of MainActivity
回答2:
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.
来源:https://stackoverflow.com/questions/28862525/android-annotations-background-networkonmainthreadexception