我想从其他服务启动一个服务不在一个活动,我做了下面的代码,但没有工作它执行块,但服务未启动。在其他服务启动服务不启动
Myservice.class
HttpPost post = new HttpPost(Constant1.URL_GET_COURSE_LIST);
String result = HTTPadapter.getDetails(post);
Log.e("resultofcourselist", "" + result);
Intent i=new Intent(getApplicationContext(),DemoService.class);
i.putExtra("result", result);
startService(i);
Demoservice.class
intent.getStringExtra("result");
try {
jsonResponse = new JSONArray(result);
jsonObject = jsonResponse.getJSONObject(0);
jsonMainNode = jsonObject.optJSONArray("rowsResponse");
//DbAdd dbAdd=new DbAdd();
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
result = jsonChildNode.optString("result").toString();
if (result.equals("Success")) {
jsonObject = jsonResponse.getJSONObject(1);
jsonMainNode = jsonObject.optJSONArray("getCourseList");
// dbAdd.setJsonMainNode(jsonMainNode);
for (int j = 0; j < jsonMainNode.length(); j++) {
// dbAdd.setJsonChildNode();
JSONObject childnode = jsonMainNode.getJSONObject(j);
Intent dbadd = new Intent(getApplicationContext(), Dbadd.class);
dbadd.putExtra("mainnode", jsonMainNode.toString());
dbadd.putExtra("childnode", childnode.toString());
// dbadd.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startService(dbadd);
}
stopSelf();
} else {
//
}
}
} catch (Exception e) {
e.printStackTrace();
}
的Manifest.xml
<service android:name=".Myservice" />
<service android:name=".DemoService" />
登录
Myservice start print in log but in demoservice on startcommand not execute
@马丁Demoservice从来没有穿过我的服务,是我的问题 – user3481301
@ user3481301的答案进行了编辑,从而使我的评论开始(和你的藏汉)过时的^^ –