Hi! I have the following issue with my Android app:
When the app gets started, I create a Service Intent checking if it already exists. If it is already created I do nothing and if it is not, then I do create it. This service will create a notification eventually. The first time the app starts it works fine, but the problem appears when I close It with the Back button and I open it again by some notification created with the service: Every time that the Ti.Platform is invoked the app crashes like if doesn't exist reference to it.
I supouse that the issue comes with the Service Intent creation because when I do not create it all works fine.
Here the steps that I already mentioned:
1) Open the app
2) Create the Service Intent in app.js
if(show == 1) { if(typeof(Ti.App.ServiceRunning) == 'undefined' || Ti.App.ServiceRunning == false) { if (typeof(Titanium.App.Android_Service) == 'undefined') { var intent = Titanium.Android.createServiceIntent( { url: 'services_Android.js', startMode: Titanium.Android.START_NOT_STICKY } ); intent.putExtra('interval', 30000);//3600000 --> 1 hour Titanium.App.Android_Service = Titanium.Android.createService(intent); } Titanium.App.Android_Service.start(); } Titanium.App.ServiceRunning = true; } else { if(typeof(Ti.App.ServiceRunning) != 'undefined' && Ti.App.ServiceRunning == true) Titanium.App.Android_Service.stop(); Titanium.App.ServiceRunning = false; }
3) Wait until the notification is created in this way
var intent = Ti.Android.createIntent({ flags: Ti.Android.FLAG_ACTIVITY_REORDER_TO_FRONT || Ti.Android.FLAG_ACTIVITY_NEW_TASK, className: 'com.tisaSoftware.BeenMissingHouston.AppActivity' }); intent.addCategory(Ti.Android.CATEGORY_LAUNCHER); // Create a PendingIntent to tie together the Activity and Intent var pendingIntent = Titanium.Android.createPendingIntent({ intent: intent, flags: Titanium.Android.FLAG_UPDATE_CURRENT }); // Create the notification var notification = Titanium.Android.createNotification({ icon: 0x7f020000, contentTitle: notificationMessage, contentText : 'Go to the application.', contentIntent: pendingIntent }); // Send the notification. Titanium.Android.NotificationManager.notify(blnHaveNewMissingPerson ? 666 : 777, notification);
4) Close the app with the "Back" button
The win has the property *exitOnClose: true*
5) Open the app again by the notification
6) The app shows error messages like this when any Ti.Platform instance is invoked:
Runtime Error
Location: [0,0] null
Message:
Source:
Runtime Error
Location: [1,0] services_Android.js
Message: Wraped java.lang.NullPointerException (services_Android.js#1)
Source:
NOTE: It only happens with some phones, but not with the emulator and some other phones. For example, we have this issue in the Samsung Galaxy S2 or S3.
Some information: Application type: mobile / Titanium SDK: 2.1.2 (08/24/12 14:46 ed7f777) / Platform & version: Android 4.0.4 / Device: Samsung Galaxy S3 / Titanium Studio: 2.0.1.201204132053
Any idea?
Your Answer
Think you can help? Login to answer this question!