0

我正在为 GCM 创建 sdk(单个 jar 文件)。如何将数据保存在 jar 文件中?

我正在设置要在用户按下通知时启动的活动类,但是在调用意图服务时,我在启动活动中设置的活动类未定义。

CustomIntentService.java

public class CustomIntentService extends GCMBaseIntentService {

    @Override
    protected void onMessage(Context context, Intent intent) {
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(R.id.icon, message, when);
        Intent notificationIntent = new Intent(context, PushManager.getActivity());
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notificationManager.notify(0, notification);
    }
}

PushManager.java

public final class PushManager {
    private Activity startupActivity;

    public void setActivity(Activity activity) {
        startupActivity = activity;
    }

    public Activity getActivity() {
        return startupActivity;
    }
}

MainActivity.java

PushManager.setActivity(this);
4

1 回答 1

0

使用首选项解决了这个问题。

于 2012-11-30T06:37:58.643 回答