[英]calling multiple methods in oncreate method in android
I have multiple methods to be called when activity is started.当活动开始时,我有多种方法可以调用。 I have added those methods in the oncreate method.
我在 oncreate 方法中添加了这些方法。 The problem is when the activity is started some methods are called some or not called.
问题是当活动开始时,某些方法会被调用或不被调用。 How do i call all the methods when the activity is started.
活动开始时如何调用所有方法。
My code is我的代码是
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
client.post("http://localhost/website/getdbrowcount.php",params ,new AsyncHttpResponseHandler()
{
public void onSuccess(String response)
{
try
{
Log.d("home", "success");
JSONObject obj = new JSONObject(response);
Log.d("home", obj.toString());
System.out.println(obj.get("count"));
syncDB();
sync();
subsync();
syncfeature();
syncelec();
syncconnector();
synccontrols();
synckeypad();
syncmech();
syncorder();
syncpower();
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void onFailure(int statusCode, Throwable error,String content)
{
if(statusCode == 404)
{
update.setText("The update has been cancelled. Please update via Settings to work"
+ " with latest Sonetonix product data");
Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
btn1.setEnabled(true);
btn1.setTextColor(Color.parseColor("#FFFFFF"));
}
else if(statusCode == 500)
{
update.setText("The update has been cancelled. Please update via Settings to work"
+ " with latest Sonetonix product data");
Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
btn1.setEnabled(true);
btn1.setTextColor(Color.parseColor("#FFFFFF"));
}
else
{
update.setText("The update has been cancelled. Please update via Settings to work"
+ " with latest Sonetonix product data");
Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]", Toast.LENGTH_LONG).show();
btn1.setEnabled(true);
btn1.setTextColor(Color.parseColor("#FFFFFF"));
}
Log.d("home", "failure");
}
});
}
In the code when OnSuccess the methods has to be called but only syncDB(),sync() is called and rest are not called .在 OnSuccess 时的代码中,必须调用方法,但只调用 syncDB(),sync() 并且不调用 rest 。 What change should i make in the code to resolve this issue.
我应该在代码中进行哪些更改来解决此问题。
Please help请帮忙
It is because in the sync()
method or possibly at the start of the subsync()
method your program is throwing an error.这是因为在
sync()
方法中或可能在subsync()
方法的开头,您的程序抛出了错误。 Because of the try/catch block, you are allowing the program to continue.由于 try/catch 块,您允许程序继续。
Check the method for an error and fix that.检查方法是否有错误并修复它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.