New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(android): Refactored app resume, intent-filter, and "newintent" handling #10519
Conversation
…dling - This commit purposely breaks startActivityOnResult() handling. To be addressed in near future.
- Fixed startActivityForResult() handling. - [TIMOB-26636] Removed deprecated "newIntent" event in favor of "newintent". - [TIMOB-26637] Added "rootActivity" property to Ti.Android module. - [TIMOB-26638] Root Ti.Android.Activity "intent" property is now updated when "newintent" is fired.
|
Perhaps I should ignore the The problem with this is that our firebase module sets this flag in the notification. So, tapping on a notification while the app's activity is backgrounded brings you back to the splash which may be confuse app developers. Thanks goes to @m1ga for discovering this. |
- Modified to ignore "Intent.FLAG_ACTIVITY_CLEAR_TOP". No longer destroys child activites. * Firebase module was setting this flag. Tapping notification caused confusion when child windows disappeared. - Now logs a warning when add event listener for "newIntent". (Must use "newintent" instead.)
Updated PR:
|
android/titanium/src/java/org/appcelerator/titanium/TiActivity.java
Outdated
Show resolved
Hide resolved
android/titanium/src/java/org/appcelerator/titanium/TiRootActivity.java
Outdated
Show resolved
Hide resolved
android/titanium/src/java/org/appcelerator/titanium/TiRootActivity.java
Outdated
Show resolved
Hide resolved
android/titanium/src/java/org/appcelerator/titanium/TiRootActivity.java
Outdated
Show resolved
Hide resolved
android/titanium/src/java/org/appcelerator/titanium/proxy/ActivityProxy.java
Show resolved
Hide resolved
FR Passed. The refactor of app resume and Studio Ver: 5.1.2.201810301430 |
Hmm... there is one more thing we have to watch out for. If you home-out of the app and leave it in the background for 30 minutes, then the Android OS might automatically destroy all of the child activity windows. This means when you resume the app after 30 minutes, you'll be brought back to the splash screen. This is mentioned by the ticket below. The above ticket handled it via "tiapp.xml" property "ti.android.root.reappears.restart", which this PR has removed. However, I think there is a better solution. In the "AndroidManifest.xml", we should set the Edit: |
…"alwaysRetainTaskState" set to true. - Prevents OS from auto-destroying child activities if app is in the background for over 30 minutes. - Replaces/deprecates "tiapp.xml" property: "ti.android.root.reappears.restart"
Need to make a couple more updates to this PR for the below shortcut related issues. Many app developers are wrongly accessing the child activity instead of the root activity for I've also seen code where a shortcut would launch a Java |
- Modified TiJSActivity derived classes to no longer display its activity. * Now launches/resume main activity with JSActivity's intent. * This feature is now obsolete due to design issues. But kept for backward compatibility. - Added undocumented Ti.App "started" event on all platforms via "ti.main.js". * Will be fired after execution of "app.js". * Currently used on Android to defer execution of JSActivity script until after "app.js" is loaded for Alloy support. - Modified all "Ti.UI.Window" child activities to call their own onNewIntent() when root activity's onNewIntent() gets called. * Maintains legacy behavior where existing Titanium apps expect intent to be copied to all child activities. - Fixed possible KrollProxy.onFireEvent() iteration exception if event listener add/removes a listener. * Was never happening in a real app, but this commit's code changes does this in "TiRootActivity.java".
Updated PR:
|
// This event is to be fired after "app.js" execution. Reasons: | ||
// - Allow system to queue startup related events until "app.js" has had a chance to add listeners. | ||
// - For Alloy apps, we now know that Alloy has been initialized and its globals were added. | ||
Ti.App.fireEvent('started'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to document this event? If this is an internal event maybe rename to _started
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a problem publicly documenting it.
@sgtcoolguy, do you have any objections? The above adds a new Ti.App
"started" event on all platforms (Android, iOS, and Windows). It is fired after "app.js" gets executed. For example, this is useful for deferring startup related events until after the "app.js" has had a chance to add listeners for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR: PASS (although, see not regarding started
event)
NOTE: minor, but there are a few places final
could be used
This is a behavioral change for JSActivities, as the newintent
is fired before the Javascript for the JSActivity is executed. I'm fine with this as it makes sense to fire it when it's received and not wait for the activity. But existing users could be caught out.
FR Passed. Studio Ver: 5.1.2.201812191831 |
JIRA:
Summary:
startActivityForResult()
can create a 2nd app instance stuck at the splash screen if an app instance already exists.Ti.Android
:Ti.UI.Window
.Ti.Android.Activity
"intent" property will now be updated when "newintent" has been fired.Ti.App.Android
already provides a "launchIntent". So, we're not losing anything.finish()
method on root activity should exit app.startActivityForResult()
since the app needs to callsetResult()
andfinish()
methods on root activity to return a result.New Intent Test:
<name/>
in "tiapp.xml".)<id>
in "tiapp.xml".)"action"
is set to"android.intent.action.MAIN"
.~/Library/Android/sdk/platform-tools
./adb shell am start -n com.appc.intent.test/.IntenttestActivity -a android.intent.action.VIEW -d https://www.google.com
"action"
is set to"https://www.google.com"
../adb shell am start -n com.appc.intent.test/.IntenttestActivity -a android.intent.action.VIEW -d https://www.appcelerator.com
"action"
is set to"https://www.appcelerator.com"
../adb shell am start -n com.appc.intent.test/.IntenttestActivity -a android.intent.action.VIEW -d https://www.google.com
"action"
is set to"https://www.google.com"
."action"
is still set to"https://www.google.com"
../adb shell am start -n com.appc.intent.test/.IntenttestActivity -a android.intent.action.VIEW -d https://www.appcelerator.com
"action"
is set to"https://www.appcelerator.com"
../adb shell am start -n com.appc.intent.test/.IntenttestActivity -a android.intent.action.VIEW -d https://www.google.com
"action"
is set to"https://www.google.com"
.Activity For Result Test:
<name/>
in "tiapp.xml".)<id>
in "tiapp.xml".)app.js
usingIntentReturnResultTest.js
code attached to TIMOB-26075.app.js
usingIntentRequestResultTest.js
code attached to TIMOB-26075."action"
set to"android.intent.action.VIEW"
."MyString"
set to"Hello World"
,"MyNumber"
set to123.456
, and"MyBoolean"
set totrue
.Result Code: 0
"."action"
set to"android.intent.action.SEND"
."response"
set to"My response"
."action"
set to"android.intent.action.MAIN"
.Result Code: 0
". (This means the other "IntentReturnTest" window instance was canceled out previously.)