【发布时间】:2015-09-17 08:54:29
【问题描述】:
我正在研究一个 Android 服务,有一个服务、一个接收器和一个活动。 我的活动使用 json 将数据发布到 Web 服务。我想在那里自动发布数据。活动为此使用 onClick 方法。我没有找到关于这个的东西。我可以为此使用可运行的方法吗?
这里是Activity的onclick方法:
@Override
public void onClick(View view) {
switch(view.getId()){
case R.id.btnPost:
if(!validate())
Toast.makeText(getBaseContext(), "Enter some data!", Toast.LENGTH_LONG).show();
// call AsynTask to perform network operation on separate thread
new HttpAsyncTask().execute("http://hmkcode.appspot.com/jsonservlet");
break;
}
}
我来自这里Android | Send “POST” JSON Data to Server
我做了一些东西,这很有效。
@Override
public void onResume() {
super.onResume();
//if(content!=null)
if (!validate())
Toast.makeText(getBaseContext(), "Enter some data!", Toast.LENGTH_LONG).show();
// call AsynTask to perform network operation on separate thread
new HttpAsyncTask().execute("http://hmkcode.appspot.com/jsonservlet");
// put your code here...
}
【问题讨论】:
-
你想什么时候发布数据?如果您想在应用程序启动时发布,您可以在 OnCreate 方法中调用它,类似的方法。
-
哦,谢谢,但我需要其他类的值。
标签: android json http post runnable