i have a GCMIntentService class which extends from GCMBaseIntentService, in this class , in the onMessage function , i would like to call a AsyncHttpResponseHandler.But when i am calling this ,
/**
* Method called on Receiving a new message from GCM server
* */
@Override
protected void onMessage(final Context context, Intent intent) {
if(aController == null)
aController = (ProjectApplication) context.getApplicationContext();//for the json test use context.getapp
Log.i(TAG, "Received message");
String message = intent.getExtras().getString(ProjectExtras.EXTRA_MESSAGE);
aController.displayMessageOnScreen(context, message);
JSONObject json;
String mMessage="";
int ID=1;
int ACTION=0;
if(message!=null){
try {
json= new JSONObject(message);
mMessage= json.optString("Message");
ID=json.optInt("u");
ACTION=json.getInt("t");
} catch (JSONException e) {
Log.e("MESSAGE", "ERROR");
e.printStackTrace();
}
}
final int _ID =ID;
final int _ACTION =ACTION;
final String _mMessage =mMessage;
getIntent(context, _ID, _ACTION,_mMessage);
}
this is my function which has SmartSyncManager.getInstance(context).getNews , in this function i am using AsyncHttpResponseHandler to get data from web service and update my local database.
private static void getIntent(final Context context, final int id, final int action , final String mMessage) {
final Intent intent = new Intent(context, ProjectMainActivity.class);
Log.d("IntentServiceId",""+ id);
Log.d("IntentServiceAction",""+ action);
switch (action) {
case HABERLER:
//intent = new Intent(context , NewsActivity.class);
final Intent newsIntent = new Intent( context, NewsDetailActivity.class);
Handler h = new Handler(Looper.getMainLooper());
h.post(new Runnable() {
@Override
public void run() {
SmartSyncManager.getInstance(context).getNews(60*30*1000, Policy.LOCAL_IF_FAILS, new CompanyUpdateCallBack<CompanyDataObject>() {
@Override
public void onStart() {
Log.e("GCMIntService", "onStart getNews");
}
@Override
public void onSuccess(List<CompanyDataObject> objects) {
CompanyDataObject object =SmartSyncDataBaseHelper.getInstance(context).getNewsById(id);
if(object!=null){
newsIntent.putExtra(ProjectExtras.EXTRA_Company_MODULE, Constant.MODULE_NEWS);
newsIntent.putExtra(ProjectExtras.EXTRA_Company_DATA_OBJECT,object);
intent.setClass(context, NewsDetailActivity.class);
}
generateNotification(context, mMessage,id,intent);
Log.e("GCMIntService", "OnSuccess getNews");
}
@Override
public void onFail(List<IKOLDataObject> objects) {
Log.e("GCMIntService", "OnFail getNews");
}
@Override
public void onFinish() {
Log.e("GCMIntService", "onFinish getNews");
}});
}
});
break;
it never gets in the any of AsyncHttpResponseHandler functions like on success or on fail. not even on start. Yet its working fine in the activity classes.Maybe because its in the switch? i tried to use runnable to make application wait for it,yet it didn't work well.
How can i make AsyncHttpResponseHandler(SmartSyncManager.getInstance(context).getSomething) work in GCMIntentService?
i just move all content of getIntent function into onMessage and its working fine. and also changed
if(object!=null){
newsIntent.putExtra(ProjectExtras.EXTRA_Company_MODULE, Constant.MODULE_NEWS);
newsIntent.putExtra(ProjectExtras.EXTRA_Company_DATA_OBJECT,object);
intent.setClass(context, NewsDetailActivity.class);
}
generateNotification(context, mMessage,id,intent);
into
if(object!=null){
newsIntent.putExtra(ProjectExtras.EXTRA_Company_MODULE, Constant.MODULE_NEWS);
newsIntent.putExtra(ProjectExtras.EXTRA_Company_DATA_OBJECT,object);
intent.setClass(context, NewsDetailActivity.class);
generateNotification(context, mMessage,id,intent);
}