Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15324] Android: Expose the status of the current activity (foreground or background) to module developers

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-10-28T21:24:30.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 22, 2013 Sprint 22 API, Release 3.2.0
ComponentsAndroid
Labelsmodule_module, qe-testadded
ReporterPing Wang
AssigneePing Wang
Created2013-09-23T23:56:08.000+0000
Updated2013-11-20T00:08:06.000+0000

Description

Cloudpush module wants to know if the current Titanium activity is in the foreground which is between a call to onResume() until a call to onPause().

Comments

  1. Ping Wang 2013-10-23

    PR: https://github.com/appcelerator/titanium_mobile/pull/4836 For FR: 1. Create a new module.
       ~/titanium_mobile/dist/mobilesdk-3.2.0-osx/mobilesdk/osx/3.2.0/titanium.py create --platform=android --type=module --name=test --id=com.appcelerator.test --android=~/android-sdks/
       
    2. Add a new method in the module source file test/src/com/appcelerator/test/TestModule.java:
       
       	@Kroll.method
       	public boolean isCurrentActivityInForeground()
       	{
       		return TiApplication.isCurrentActivityInForeground();
       	}
       
    3. Add the above module to a mobile project and paste the below code to app.js.
       var test = require("com.appcelerator.test");
       
       var win = Ti.UI.createWindow({
       	backgroundColor: "white"
       });
       
       var b = Ti.UI.createButton({
       	title: "isCurrentActivityInForeground"
       });
       
       b.addEventListener("click", function(){
       	alert("foreground: " + test.isCurrentActivityInForeground());
       });
       
       win.add(b);
       win.open();
       
    4. Run the project. Click the button. Should see an alert "foreground: true".
  2. Paul Lv 2013-10-29

    [~pwang] [~hpham] Could you please let me know when and which version of Titanium SDK I can use, that contains this code change? I may want to implement this on ti.cloudpush side earlier.
  3. Ping Wang 2013-10-29

    [~plv], the PR was merged yesterday so it should be in the latest [CI build](http://builds.appcelerator.com.s3.amazonaws.com/index.html#master)

JSON Source