Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour #42

Closed
bert-w opened this issue Feb 21, 2017 · 18 comments
Closed

Inconsistent behaviour #42

bert-w opened this issue Feb 21, 2017 · 18 comments

Comments

@bert-w
Copy link

bert-w commented Feb 21, 2017

02-21 10:57:19.413: E/AndroidRuntime(28868): FATAL EXCEPTION: AsyncTask #4
02-21 10:57:19.413: E/AndroidRuntime(28868): Process: com.mytitaniumapp, PID: 28868
02-21 10:57:19.413: E/AndroidRuntime(28868): java.lang.NullPointerException: Attempt to invoke virtual method 'void ti.goosh.TiGooshModule.sendMessage(java.lang.String, java.lang.Boolean)' on a null object reference
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at ti.goosh.IntentService.parseNotification(IntentService.java:130)
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at ti.goosh.IntentService.onMessageReceived(IntentService.java:54)
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at com.google.android.gms.gcm.GcmListenerService.zzq(Unknown Source)
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at com.google.android.gms.gcm.GcmListenerService.zzp(Unknown Source)
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at com.google.android.gms.gcm.GcmListenerService.zzo(Unknown Source)
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at com.google.android.gms.gcm.GcmListenerService.zza(Unknown Source)
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at com.google.android.gms.gcm.GcmListenerService$1.run(Unknown Source)
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
02-21 10:57:19.413: E/AndroidRuntime(28868): 	at java.lang.Thread.run(Thread.java:818)

Any clue on why the above error happens? This module seems quite unstable at times. Am I missing some manifest rules? I'm testing a few situations here:

  • App in background (push notification is received, but opening it will not trigger a TiGoosh callback function)
  • App is in foreground (push notification is not visible in menu, but callback triggers as its supposed to)
  • App is inactive (push notification is received, but opening it will not trigger a callback. It will just open the app)

Platform: Sony Xperia Z3 Compact, Android 6.0.1

@progress44
Copy link
Contributor

Are you using FCM?

@bert-w
Copy link
Author

bert-w commented Feb 21, 2017

GCM/FCM yea (it still seems to be in a transitional phase)

@progress44
Copy link
Contributor

It's a known issue. It has to do with the payload. It's not formatted correctly. Check out the documentation on how to send the correct payload.

@bert-w
Copy link
Author

bert-w commented Feb 21, 2017

you mean the double data key? because i am sending it, and at times it works, but occasionally the above error happens. I cant yet reproduce a solid testcase for this though

@progress44
Copy link
Contributor

can you provide the code of how you use the module?

@bert-w
Copy link
Author

bert-w commented Feb 21, 2017

i've made a bunch of code around it, but it boils down to the wiki examples:

var TiGoosh = require('ti.goosh');
TiGoosh.registerForPushNotifications({
                    success: self._success.bind(self),
                    error: self._error.bind(self),
                    callback: self._callback.bind(self)
 });

Then the _callback function prints the data for me in the console and handles the rest. However, by looking at the debug log you can see that the reported error is Java related, so however I implement it, it should not throw a NullPointer but instead show an error message that explains the error.

Here's a snippet from the tiapp.xml:

<application android:debuggable="false"
                android:hardwareAccelerated="true"
                android:icon="@drawable/appicon"
                android:label="MyTitaniumApp"
                android:largeHeap="true" android:theme="@style/Theme.Custom">
                <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
                <activity android:label="@string/app_name"
                    android:launchMode="standard"
                    android:alwaysRetainTaskState="true"
                    android:name=".MyTitaniumAppActivity" android:theme="@style/Theme.Titanium">
                    <intent-filter>
                        <action android:name="android.intent.action.VIEW"/>
                        <category android:name="android.intent.category.DEFAULT"/>
                        <category android:name="android.intent.category.BROWSABLE"/>
                        <data android:scheme="mycustomurlscheme"/>
                    </intent-filter>
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN"/>
                        <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>
                </activity>
            </application>

@progress44
Copy link
Contributor

You've given three scenarios in the original comment but not specified when the error happens.

@bert-w
Copy link
Author

bert-w commented Feb 21, 2017

I know, unfortunately I cant tell when exactly it happens, but if i would estimate:

  • Open your app, send a push notification to it (while app is in foreground), everything should work and the callback function is called.
  • After this, go to home menu on Android (taking the app to the background), send a push notification, click it, see error in console

@progress44
Copy link
Contributor

Have you checked the following closed issues:
#39
#36
#35

@bert-w
Copy link
Author

bert-w commented Feb 21, 2017

i've checked my API for the third time, im sending the nested data attribute as its supposed to. For some reason, when I kill my app/put it in background, and repeat that 2-3 times in various order, the error above will be thrown. I cant really say if its the module or something with the way the Titanium app Activitys are managed

@bert-w
Copy link
Author

bert-w commented Feb 21, 2017

Im also getting

02-21 16:17:24.421: E/GooglePlayServicesUtil(9648): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.

but I cant say if its related. Push Notifications work fine on initial app load

@progress44
Copy link
Contributor

The last one isn't related and it shouldn't be considered. It could be something with the Activity. Will make some tests as soon as I have some time

@bert-w
Copy link
Author

bert-w commented Feb 22, 2017

Please do. Let me know when you need me to test something on the newest branch.

@bert-w
Copy link
Author

bert-w commented Feb 22, 2017

I just noticed gittio has v2.0.2 while github has v2.0.0 as the latest release. I've been running 2.0.0 all the time

@progress44
Copy link
Contributor

Well, let me know if it fixes the issue
https://github.com/caffeinalab/ti.goosh/releases/tag/v2.0.2

@bert-w
Copy link
Author

bert-w commented Mar 2, 2017

Unfortunately I'm getting the exact same error using 2.0.2.

I was previously using the gcm api endpoint ( https://gcm-http.googleapis.com/gcm/send ) but I've now changed it to fcm ( https://fcm.googleapis.com/fcm/send ). It did not make a difference though.

However I noticed in the tigoosh readme that you are sending notification data also in the data object, while fcm explicitly wants separate objects like: "to" + "notification" + "data" (as seen here https://firebase.google.com/docs/cloud-messaging/server ). I've tried both syntaxes out but it still shows the same error message depending on background/foreground:

  • Currently, as soon as I send a notification while having my app in the foreground, it shows the above error.
  • When it is in the background, and I use the FCM syntax (which is a separate notification object in the JSON request) it shows:
03-02 12:21:15.721: E/TiLaunchActivity(31622): (main) [38328,38328] Android issue 2373 detected (missing intent CATEGORY_LAUNCHER or FLAG_ACTIVITY_RESET_TASK_IF_NEEDED), restarting app. MyAppActivity@ac7fdb4
  • The above error does not show when using the GCM syntax (having the app in background). However, having the app in foreground and sending the data exactly as in the PHP example in the readme, it shows the error in post 1.

@bert-w
Copy link
Author

bert-w commented Mar 2, 2017

okay I think i've found a cause of the problem. I wasnt consistently calling require('ti.goosh') in my javascript, since I had an if-statement around it which checked if I had already registered the token.

I guess you will always need to call the ti.goosh module since it has to attach some Java stuff?

@progress44
Copy link
Contributor

Yes that is correct. The module needs to be instantiated every time you lunch the app since it handles any incoming notification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants