在我的演示项目中,我使用 GCM 来接收推送消息。我需要以同步方式处理我收到的推送消息。一旦我收到推送,我需要执行一些任务并将确认发送到我的服务器(确认由异步任务发送)。我的项目正在运行在正常情况下很好,但是如果我关闭我的数据连接并且如果我发送 10 条推送消息然后我打开我的手机的数据连接,我的 GCM 会被挂起,因为它接收到一堆消息,之后它不会处理我的推。请帮助解决这个问题
MyGCMService.java
public class MyGCMService extends GCMBaseIntentService{
.....
public GCMIntentService() {
...
myThreadClass =new MyThreadClass();
}
@Override
protected void onRegistered(Context context, String registrationId) {
....
}
@Override
protected void onUnregistered(Context context, String registrationId) {
....
}
@Override
protected void onMessage(Context context, Intent intent) {
try{
// System.out.println("*********** 4-3- "+String.valueOf(myThreadClass.getState()).equals("NEW"));
if(String.valueOf(myThreadClass.getState()).equals("NEW"))
myThreadClass.start();
}catch(Exception e){
}
synchronized (myThreadClass) {
...
myThreadClass.wait();
}
}
@Override
protected void onDeletedMessages(Context context, int total) {
...
}
@Override
public void onError(Context context, String errorId) {
....
}
@Override
protected boolean onRecoverableError(Context context, String errorId) {
....
}
public void OnDestroy() {
super.onDestroy();
}
}
MyTreadClass.java
public class MyThreadClass extends Thread {
MyThreadClass myThreadClass;
String LOG_TAG = MyThreadClass.class.getSimpleName();
public void run() {
synchronized (this) {
Looper.prepare();
performAction();
notify();
}
}
public MyThreadClass() {
myThreadClass=this;
}
public void performMDMAction() {
//Doing Some task and Sending Ack. through Async task
}
}
一旦这个线程挂起我的 GCMBaseIntentService,就不会调用 Override OnMessage() 函数。
提前致谢