当用户点击城市飞艇通知时重新启动android应用程序

当用户点击城市飞艇通知时重新启动android应用程序,android,notifications,urbanairship.com,Android,Notifications,Urbanairship.com,我已经成功安装了一个android应用程序,可以使用城市飞艇接收通知,但是在处理PushManager时遇到了问题。我的BroadcastReceiver正在工作,正在接收消息并调用以下内容(来自示例代码): 这可以很好地工作,并将主要活动带回前台,但应用程序不再运行的情况除外。如果我向手机发送通知,关闭应用程序,然后打开通知,应用程序会因NullPointerException崩溃: Failed to load meta-data, NullPointer: null Unable to t

我已经成功安装了一个android应用程序,可以使用城市飞艇接收通知,但是在处理PushManager时遇到了问题。我的BroadcastReceiver正在工作,正在接收消息并调用以下内容(来自示例代码):

这可以很好地工作,并将主要活动带回前台,但应用程序不再运行的情况除外。如果我向手机发送通知,关闭应用程序,然后打开通知,应用程序会因NullPointerException崩溃:

Failed to load meta-data, NullPointer: null
Unable to takeOff automatically
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start receiver com.urbanairship.CoreReceiver:         java.lang.NullPointerException
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2236)
at android.app.ActivityThread.access$1500(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
我不知道是什么原因造成的。有什么想法吗?

好的,想清楚了

我是从活动上下文而不是应用程序上下文实例化UrbanAirship并注册IntentReceiver


哎呀。

我遇到了同样的问题。我将UAirship初始化放在应用程序的onCreate中,而不是活动中,从而解决了这个问题

你好,Amit Jayaswal,请参见以下示例:

公共类MyApplication扩展了应用程序{

@Override
public void onCreate() {
    super.onCreate();

    // Optionally, customize your config at runtime:
    //
    // AirshipConfigOptions options = new AirshipConfigOptions();
    // options.inProduction = false;
    // options.developmentAppKey = "Your Development App Key";
    // options.developmentAppSecret "Your Development App Secret";
    //
    // UAirship.takeOff(this, options);

    UAirship.takeOff(this, new UAirship.OnReadyCallback() {
        @Override
        public void onAirshipReady(UAirship airship) {
            // Perform any airship configurations here

            // Create a customized default notification factory
            DefaultNotificationFactory defaultNotificationFactory = new DefaultNotificationFactory(getApplicationContext());
            defaultNotificationFactory.setSmallIconId(R.drawable.ic_notification);
            //defaultNotificationFactory.setColor(NotificationCompat.COLOR_DEFAULT);

            // Set it
            airship.getPushManager().setNotificationFactory(defaultNotificationFactory);

            // Enable Push
            airship.getPushManager().setPushEnabled(true);
        }
    });
}

}

你能分享一下代码吗?我也遇到了同样的问题。?请帮助我@TomBomb。
@Override
public void onCreate() {
    super.onCreate();

    // Optionally, customize your config at runtime:
    //
    // AirshipConfigOptions options = new AirshipConfigOptions();
    // options.inProduction = false;
    // options.developmentAppKey = "Your Development App Key";
    // options.developmentAppSecret "Your Development App Secret";
    //
    // UAirship.takeOff(this, options);

    UAirship.takeOff(this, new UAirship.OnReadyCallback() {
        @Override
        public void onAirshipReady(UAirship airship) {
            // Perform any airship configurations here

            // Create a customized default notification factory
            DefaultNotificationFactory defaultNotificationFactory = new DefaultNotificationFactory(getApplicationContext());
            defaultNotificationFactory.setSmallIconId(R.drawable.ic_notification);
            //defaultNotificationFactory.setColor(NotificationCompat.COLOR_DEFAULT);

            // Set it
            airship.getPushManager().setNotificationFactory(defaultNotificationFactory);

            // Enable Push
            airship.getPushManager().setPushEnabled(true);
        }
    });
}