Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Pass data from an Android local notification, to a minimised app

$
0
0

I'm using TiSDK 3.2.0GA on Android.

I can successfully create a local notification using bencoding.alarmmanager with the following code in a background service:

var activity = Ti.Android.currentActivity;    
    var intent = Ti.Android.createIntent({
        action : Ti.Android.ACTION_MAIN,
        className : 'com.myapp.android.MyappActivity',
        flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP
    });
    intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER);
    intent.putExtra('com.myapp.android.USER_INFO', JSON.stringify(info.data));
 
    var pending = Ti.Android.createPendingIntent({
        activity : activity,
        intent : intent,
        type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
        flags : Ti.Android.FLAG_ACTIVITY_NO_HISTORY
    });
 
    var cfg = {
        contentIntent : pending,
        contentTitle : info.title,
        contentText : info.message,
        tickerText : info.message,
        when : 0,
        icon : info.icon,
        flags : Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS | Titanium.Android.FLAG_INSISTENT,
        sound : Titanium.Android.NotificationManager.DEFAULT_SOUND
    };
 
    var notification = Ti.Android.createNotification(cfg);
 
    if (info.sound)
    {
        Ti.Media.createSound({url: info.sound}).play(); 
    }
 
    Ti.Android.NotificationManager.notify(1, notification);
The following line (used above) allows passing data to the app if the app IS NOT running:
intent.putExtra('com.myapp.android.USER_INFO', JSON.stringify(info.data));
... and then using the following to receive the data inside the app, after the resume event:
var info = Ti.Android.currentActivity.getIntent().getStringExtra('com.myapp.android.USER_INFO');
This doesn't work when the app IS running in the background (minimised). The app is correctly maximised (rather than a new instance created), but the line above doesn't work.

Any help would be greatly appreciated.


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>