App type : Mobile
Android SDK - 18
TiSDK - 3.2.1
My app is alarm manger kind not i set alarm and i move to background and i used https://github.com/benbahrenburg/benCoding.AlarmManager and register for background service but when it fire background service it gives current activity null . App not start from background. it run successfull but
Titanium.API.info(‘————- activity———:’ + JSON.stringify(activity)); is null.
How to Start Ap[p from background
alarmManager.addAlarmService({ service:”com.custom.alarmapp.CustomalarmService”, year : dt.getFullYear(), month : dt.getMonth(), day : dt.getDate(), hour : dt.getHours(), minute : dt.getMinutes(), //Set the number of minutes until the alarm should go off userInfo : { “notificationData” : { date : selectedDateForDb.toString(), dbid : lastInsertedRow, alarmtimeid : alarmtime_id } } });and in my TiApp.xml android part
<android xmlns:android="http://schemas.android.com/apk/res/android"> <manifest android:versionCode="1" android:versionName="1.0" package="com.custom.alarmapp" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="18"/> <application android:background="@color/transparent" android:debuggable="false" android:icon="@drawable/appicon" android:label="AlarmApp" android:name="AlarmappApplication"> <activity android:configChanges="keyboardHidden" android:label="@string/app_name" android:launchMode="singleTop" android:name=".AlarmappActivity" android:screenOrientation="portrait" android:theme="@style/Theme.Titanium"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:configChanges="keyboardHidden" android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait"/> <activity android:configChanges="keyboardHidden" android:name="org.appcelerator.titanium.TiTranslucentActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent"/> <activity android:configChanges="screenSize" android:name="ti.modules.titanium.ui.android.TiPreferencesActivity" android:screenOrientation="portrait"/> <service android:exported="false" android:name="org.appcelerator.titanium.analytics.TiAnalyticsService"/> </application> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> </manifest> <services> <service url="customalarm.js"/> </services> </android>below is my customalarm.js
var service = Ti.Android.currentService; var serviceIntent = service.getIntent(); //var userInfo = JSON.parse(serviceIntent.getExtra(“userInfo”)); var playAlarm = function() { Titanium.API.info(‘————- Servvicve———’); var activity = Ti.Android.currentActivity; var intent = Ti.Android.createIntent({ action : Ti.Android.ACTION_MAIN, className : ‘com.custom.alarmapp.AlarmappActivity’, flags : Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_NEW_TASK, }); Titanium.API.info(‘————- activity———:’ + JSON.stringify(activity)); intent.addCategory(Ti.Android.CATEGORY_LAUNCHER); activity.startActivity(intent); }; playAlarm(); Ti.Android.stopService(serviceIntent);