Skip to content
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

[6_0_X][TIMOB-24497][TIMOB-24316][TIMOB-24527] Backport #8910

Merged
merged 7 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3593,6 +3593,16 @@ AndroidBuilder.prototype.generateAndroidManifest = function generateAndroidManif
}, this);
}, this);

// TIMOB-15253: Titanium Android cannot be used with 'android:launchMode' as it can dispose the KrollRuntime instance
// prevent 'android:launchMode' from being defined in the AndroidManifest.xml
for (var activity in tiappAndroidManifest.application.activity) {
var parameters = tiappAndroidManifest.application.activity[activity];
if (parameters['launchMode']) {
delete parameters['launchMode'];
this.logger.warn(__('%s should not be used. Ignoring definition from %s', 'android:launchMode'.red, activity.cyan));
}
}

// gather activities
var tiappActivities = this.tiapp.android && this.tiapp.android.activities;
tiappActivities && Object.keys(tiappActivities).forEach(function (filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ private static void syncInit()
// to execute on the runtime, and we can therefore dispose of it.
public static void incrementActivityRefCount()
{
waitForInit();

activityRefCount++;
if ((activityRefCount + serviceReceiverRefCount) == 1 && instance != null) {
syncInit();
Expand Down Expand Up @@ -399,6 +401,8 @@ public static int getActivityRefCount()
// Similar to {@link #incrementActivityRefCount} but for a Titanium Service.
public static void incrementServiceReceiverRefCount()
{
waitForInit();

serviceReceiverRefCount++;
if ((activityRefCount + serviceReceiverRefCount) == 1 && instance != null) {
syncInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected void onResume()
if (intent.getComponent().getClassName().equals(TiActivity.class.getName())) {
Intent newIntent = new Intent(intent);
newIntent.putExtras(rootIntent);
newIntent.setData(rootIntent.getData());
setIntent(newIntent);

// fire 'newintent'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.appcelerator.titanium;

import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.KrollRuntime;
import org.appcelerator.titanium.util.TiActivitySupport;
import org.appcelerator.titanium.util.TiRHelper;

Expand All @@ -18,6 +19,8 @@
import android.os.Bundle;
import android.view.Window;

import java.util.Set;

public class TiRootActivity extends TiLaunchActivity
implements TiActivitySupport
{
Expand Down Expand Up @@ -78,8 +81,45 @@ protected void onCreate(Bundle savedInstanceState)

if (intent != null) {
if (rootActivity != null) {

// TIMOB-24527: FLAG_ACTIVITY_NEW_DOCUMENT creates a new activity instance
// which overrides any previous event handlers and prevents resumed instances
// from functioning correctly. We need to ignore this flag.
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) {
intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
finish();
startActivity(intent);

KrollRuntime.incrementActivityRefCount();
activityOnCreate(savedInstanceState);
return;
}
rootActivity.setIntent(intent);
} else {

// TIMOB-24497: launching as CATEGORY_HOME or CATEGORY_DEFAULT prevents intent data from
// being passed to our resumed activity. Re-launch using CATEGORY_LAUNCHER.
Set<String> categories = intent.getCategories();
if (categories == null || categories.contains(Intent.CATEGORY_HOME) || !categories.contains(Intent.CATEGORY_LAUNCHER)) {
finish();

if (categories != null) {
for (String category : categories) {
intent.removeCategory(category);
}
}
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);

restartActivity(100, 0);

KrollRuntime.incrementActivityRefCount();
activityOnCreate(savedInstanceState);
return;
}
}

// TIMOB-15253: implement 'singleTask' like launchMode as android:launchMode cannot be used with Titanium
if (tiApp.intentFilterNewTask() &&
intent.getAction() != null && intent.getAction().equals(Intent.ACTION_VIEW) &&
intent.getDataString() != null &&
Expand All @@ -92,7 +132,8 @@ protected void onCreate(Bundle savedInstanceState)
startActivity(intent);
finish();

super.onCreate(savedInstanceState);
KrollRuntime.incrementActivityRefCount();
activityOnCreate(savedInstanceState);
return;
}
}
Expand Down
5 changes: 5 additions & 0 deletions apidoc/Titanium/Android/Android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ description: |
For more information about intent filters, see the
[Android Intent Filters guide](http://docs.appcelerator.com/platform/latest/#!/guide/Android_Intent_Filters).

#### Launch Modes

Defining launch modes using `android:launchMode` is not supported by Titanium Android.
However, `singleTask` behaviour can be accomplished when using [intent filters](http://docs.appcelerator.com/platform/latest/#!/guide/Android_Intent_Filters).

#### Notifications

Notifications alert the user that something is happening to your application while it is
Expand Down