What I want to achieve here is that when users click the notification, the app will open and switch to the corresponded tab within a tab group. It was working, but not anymore now. I can't find the cause. I did update the studio and sdk to 3.2.2, but even if I rolled back to an older sdk, it still didn't work. Example:
app.js
var tabgroup = require('tab'); var nNot = 0; function notify(type) { var title = null, text = null, url = null; switch (type) { case 'download': url = 'download.js'; title = 'Downloading file...'; text = 'Click here to see download details'; break; case 'music': url = 'music.js'; title = 'Music playing...'; text = 'Click here to see music details'; break; default: return; } var intent = Ti.Android.createIntent({ action: Ti.Android.ACTION_VIEW, flags: Ti.Android.FLAG_ACTIVITY_NEW_TASK, url: url }); var pending = Titanium.Android.createPendingIntent({intent: intent}); var notification = Titanium.Android.createNotification({ number: nNot++, contentTitle : title, contentText : text, contentIntent : pending }); Titanium.Android.NotificationManager.notify(nNot, notification); } // create the downloading window var win1 = Ti.UI.createWindow({layout: 'vertical'}); var btn1 = Ti.UI.createButton({title: 'Download'}); var lbl1 = Ti.UI.createLabel({text: ''}); var downloading = false; btn1.addEventListener('click', function(e) { // not really downloading anything, just create a notification if (!downloading) { lbl1.text = 'Download in progress...'; notify('download'); } else { lbl1.text = ''; } downloading = !downloading; }); win1.add(lbl1); win1.add(btn1); var tab1 = Ti.UI.createTab({ window : win1, title : 'Download' }); // create the music page var win2 = Ti.UI.createWindow({layout: 'vertical'}); var btn2 = Ti.UI.createButton({title : 'Toggle music'}); var music = Ti.Media.createAudioPlayer({ url: "/somesong.mp3", autoplay: false, allowBackground: true }); var playing = false; btn2.addEventListener('click', function(e) { if (!playing) { music.play(); notify('music'); } else { music.stop(); } playing = !playing; }); win2.add(btn2); var tab2 = Ti.UI.createTab({ window : win2, title : 'Music' }); tabgroup.addTab(tab1); tabgroup.addTab(tab2); tabgroup.open();tab.js
(function() { module.exports = Ti.UI.createTabGroup(); })();download.js
var win = Ti.UI.currentWindow; win.close(); var tab = require('tab'); tab.setActiveTab(0);music.js
var win = Ti.UI.currentWindow; win.close(); var tab = require('tab'); tab.setActiveTab(1);tiapp.xml
<android xmlns:android="http://schemas.android.com/apk/res/android"> <activities> <activity url="download.js"> <intent-filter><action android:name="android.intent.action.VIEW"/></intent-filter> </activity> <activity url="music.js"> <intent-filter><action android:name="android.intent.action.VIEW"/></intent-filter> </activity> </activities> </android>anyone has any ideas? Greatly appreciated!