I use C2DM with PhoneGap. When I receive a C2DM message, I show a notification (via NotificationManager ). When a user selects a notification, my application receives the intention. In this case, I want to activate the page in my jquery-mobile webapp.
So I flipped the onNewIntent event to keep the intent:
@Override protected void onNewIntent(final Intent intent) { super.onNewIntent(intent); setIntent(intent); }
Then in onResume I activated the correct page if the target was from C2DM:
@Override protected void onResume() { super.onResume(); // read possible argument boolean showMessage = getIntent().getBooleanExtra(ARG_SHOW_MESSAGES, false); if (showMessage) { clearNotification(); super.loadUrl("file:///android_asset/www/de/index.html#messages"); } }
This works great, but sometimes it crashes with a NullPointerException - not on my mobile device or emulator, but on other devices. The stack stack says it is in the onNewIntent activity, see Code :
protected void onNewIntent(Intent intent) { super.onNewIntent(intent);
I could not reproduce this situation. Obviously pluginManager is NULL, but I don't know why.
So the questions are:
- Is the approach suitable for selecting a specific page in jquery-mobile with Android, or can someone suggest a better approach?
- How can I get rid of an exception? Of course, I can check the pluginManager for the absence of a zero value and in this case do not call it super - but then my specific page is not activated.
- Do you think this is PhoneGap error - not checking pluginmanager for null? When I checked the PhoneGap code, I thought that this should never happen, in my understanding, onNewIntent is only called when activity is loaded, otherwise the onCreate action will be activated.
Update Now I know more: the problem occurs when the application does not load and the C2DM message appears. The goal begins with the application, events occur in the following order - but onNewIntent is called only occasionally:
onCreate() onNewIntent() onResume()
Whenever onNewIntent is executed during startup, it fails. Anyway, I fixed it with
@Override protected void onNewIntent(final Intent intent) {
When I want to change the start page in onResume-Event, this does not work if Phonegap is not ready. Thus, it is only too early to call the #messages page in onResume in the case when the application starts. But when to call? Is it possible to connect to onDeviceReady?