Skip to content

Instantly share code, notes, and snippets.

@iotashan
Last active March 2, 2017 15:18
Show Gist options
  • Save iotashan/8004d5929049843e8597 to your computer and use it in GitHub Desktop.
Save iotashan/8004d5929049843e8597 to your computer and use it in GitHub Desktop.
Listening for android start/pause/stop/resume events in Titanium
if (OS_ANDROID) {
// Somehow, only in alloy.js we can get the data (URL) that opened the app
Alloy.Globals.url = Ti.Android.currentActivity.intent.data;
Ti.API.info('launch data: '+Ti.Android.currentActivity.intent.data);
Ti.Android.currentActivity.addEventListener('newintent',function(e){
Ti.API.info('newintent ' + JSON.stringify(e.intent.data));
});
Ti.Android.currentActivity.onCreate = function(e){
Ti.API.info('onCreate ' + JSON.stringify(e));
};
Ti.Android.currentActivity.onDestroy = function(e){
Ti.API.info('onDestroy ' + JSON.stringify(e));
};
Ti.Android.currentActivity.onPause = function(e){
Ti.API.info('onPause ' + JSON.stringify(e));
};
Ti.Android.currentActivity.onRestart = function(e){
Ti.API.info('onRestart ' + JSON.stringify(e));
};
Ti.Android.currentActivity.onResume = function(e){
Ti.API.info('onResume ' + JSON.stringify(e));
};
Ti.Android.currentActivity.onStart = function(e){
Ti.API.info('onStart ' + JSON.stringify(e));
};
Ti.Android.currentActivity.onStop = function(e){
Ti.API.info('onStop ' + JSON.stringify(e));
};
}
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest android:installLocation="preferExternal"
android:versionCode="1" android:versionName="1.0.0">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19"/>
<supports-screens android:anyDensity="true"
android:largeScreens="true" android:normalScreens="true" android:smallScreens="false"/>
<application android:label="MyApp" android:theme="@style/Theme.MyApp">
<activity android:alwaysRetainTaskState="true"
android:label="MyApp" android:name=".MyAppActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="myapp"/>
</intent-filter>
</activity>
<activity android:label="MyApp"
android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
</application>
</manifest>
</android>
@joshualambert
Copy link

Very helpful. Thank you, @iotashan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment