关于Intentsetvice
public class Loginservice extends IntentService{
public Loginservice(String name) {
super(name);
}
public Loginservice() {
//必须实现父类构造方法
super("Loginservice");
}
@Override
protected void onHandleIntent(Intent intent) {
final String userID=intent.getExtras().getString("userID");
boolean isLogined=intent.getExtras().getBoolean("isLogined");
if (!TextUtils.isEmpty(userID) && isLogined) {
AsyncRunner.HttpGet(new BaseRequestListener() {
@Override
public void onBarfooError(BarfooError e) {
super.onBarfooError(e);
}
@Override
public void onRequesting() throws BarfooError, JSONException {
Bundle bundle = new Bundle();
bundle.putString("userId", userID);
JSONObject response = BaseHttp.httpGet(BaseHttp.build_api(
"http://222.175.186.6:8214/GetChannelByUId", bundle));
LogUtil.i("getUserChannelsFromServer:" + response.toString()+"==========");
String selected = response.getJSONObject("Data").getString("selected");
String unselected = response.getJSONObject("Data").getString("unSelected");
String[] selectedStr = selected.split(",");
String[] unselectedStr = unselected.split(",");
// 由于服务器返回的栏目只是栏目ID,这里需要转化成栏目实体
ArrayList<Channel> selectedChannels = longinUtil.getUserSelectedChannels(selectedStr);
ArrayList<Channel> unselectedChannels = longinUtil.getUserUnselectedChannels(unselectedStr);
longinUtil.updateUserChannels(selectedChannels, unselectedChannels);
}
});
}
}
//启动Intentservice与service一样
startService(intent);
//注册service
<service android:name=".service.Loginservice">
<intent-filter >
<action android:name="urun.news.service.Loginservice"/>
</intent-filter>
</service>