错误:The method setDefaultPushCallback(Context, Class<? extends Activity>) in the type PushService is not applicable for the arguments (new Runnable(){}, Class<MenuActivity>)
解析推送通知教程
上面的错误显示
try {
runOnUiThread(new Runnable() {
public void run() {
GetOtherData getOtherData = new GetOtherData();
getOtherData.execute();
PushService.setDefaultPushCallback(this, MenuActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseAnalytics.trackAppOpened(getIntent());
}
});
} catch (Exception e) {
e.printStackTrace();
}
您应该使用getApplicationContext()
或yourActivity.this
来获取上下文。像这样…
try {
runOnUiThread(new Runnable() {
public void run() {
GetOtherData getOtherData = new GetOtherData();
getOtherData.execute();
PushService.setDefaultPushCallback(YourActivity.this, MenuActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseAnalytics.trackAppOpened(getIntent());
}
});
} catch (Exception e) {
e.printStackTrace();
}
我也遇到了同样的问题。在setDefaultPushCallback中,你应该指定当用户按下返回按钮时显示的活动。我可以通过修改这一行来编译:
PushService.setDefaultPushCallback(this, MenuActivity.class)
对于这个:
PushService.setDefaultPushCallback(this, MainActivity.class)
检查android parse-xxx.jar
的版本号(xxx是版本号),如果你使用旧版本,方法setDefaultPushCallback
将不适用,我在使用parse1.4.4.jar