Skip to content

Commit

Permalink
Apptentive Android SDK 4.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
skykelsey committed Jan 4, 2018
1 parent 5108dcd commit 2d62ae2
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 2018-01-03 - v4.1.4

#### Bugs Fixed

* Fix a NullPointerException that occurs when the Apptentive SDK is included in an Instant App, and the host app's Activity is not available when exiting the Apptentive UI.
* Fixed a potential crash when used in Instant Apps that don't contain a launcher Activity.
* Don't send payloads when the app is in the background.
* Don't poll for messages when the app is in the background.


# 2017-12-02 - v4.1.3

#### Bugs Fixed
Expand Down Expand Up @@ -29,6 +39,15 @@
* Fix global configuration fetching
* Fix Love Dialog to stack buttons if their labels are too long

# 2018-01-03 - v4.0.3

#### Bugs Fixed

* Fixed a potential crash when used in Instant Apps that don't contain a launcher Activity.
* Don't send payloads when the app is in the background.
* Don't poll for messages when the app is in the background.
* Fixed global Configuration polling.

# 2017-08-15 - v4.0.2

#### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,17 @@ private void startLauncherActivityIfRoot() {
if (isTaskRoot()) {
PackageManager packageManager = getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(getPackageName());
ComponentName componentName = intent.getComponent();
/** Backwards compatible method that will clear all activities in the stack. */
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
startActivity(mainIntent);
/*
Make this work with Instant Apps. It is possible and even likely to create an Instant App
that doesn't have the Main Activity included in its APK. In such cases, this Intent is null,
and we can't do anything apart from exiting our Activity.
*/
if (intent != null) {
ComponentName componentName = intent.getComponent();
// Backwards compatible method that will clear all activities in the stack.
Intent mainIntent = Intent.makeRestartActivityTask(componentName);
startActivity(mainIntent);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class ConversationManager {

private final WeakReference<Context> contextRef;

private boolean appIsInForeground;

/**
* A basic directory for storing conversation-related data.
*/
Expand All @@ -101,6 +103,7 @@ public ConversationManager(Context context, File apptentiveConversationsStorageD
@Override
public void onReceiveNotification(ApptentiveNotification notification) {
assertMainThread();
appIsInForeground = true;
if (activeConversation != null && activeConversation.hasActiveState()) {
ApptentiveLog.v(CONVERSATION, "App entered foreground notification received. Trying to fetch app configuration and interactions...");
final Context context = getContext();
Expand All @@ -113,6 +116,15 @@ public void onReceiveNotification(ApptentiveNotification notification) {
}
}
});

ApptentiveNotificationCenter.defaultCenter()
.addObserver(NOTIFICATION_APP_ENTERED_BACKGROUND, new ApptentiveNotificationObserver() {
@Override
public void onReceiveNotification(ApptentiveNotification notification) {
assertMainThread();
appIsInForeground = false;
}
});
}

//region Conversations
Expand Down Expand Up @@ -456,8 +468,12 @@ private void handleConversationStateChange(Conversation conversation) {
ObjectUtils.toMap(NOTIFICATION_KEY_CONVERSATION, conversation));

if (conversation.hasActiveState()) {
conversation.fetchInteractions(getContext());
conversation.getMessageManager().startPollingMessages();
if (appIsInForeground) {
// ConversationManager listens to the foreground event to fetch interactions when it comes to foreground
conversation.fetchInteractions(getContext());
// Message Manager listens to foreground/background events itself
conversation.getMessageManager().attemptToStartMessagePolling();
}

// Fetch app configuration
fetchAppConfiguration(conversation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,10 @@ public void destroy() {

//region Polling

public void startPollingMessages() {
pollingWorker.startPolling();
public void attemptToStartMessagePolling() {
if (conversation.isMessageCenterFeatureUsed()) {
pollingWorker.startPolling();
}
}

public void stopPollingMessages() {
Expand Down Expand Up @@ -536,6 +538,7 @@ private void setCurrentForegroundActivity(Activity activity) {
}

public void setMessageCenterInForeground(boolean bInForeground) {
conversation.setMessageCenterFeatureUsed(true);
pollingWorker.setMessageCenterInForeground(bInForeground);
}

Expand Down Expand Up @@ -572,7 +575,9 @@ protected void execute() {

private void appWentToForeground() {
appInForeground.set(true);
pollingWorker.appWentToForeground();
if (conversation.isMessageCenterFeatureUsed()) {
pollingWorker.appWentToForeground();
}
}

private void appWentToBackground() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MessagePollingWorker implements Destroyable {
conf = Configuration.load();
backgroundPollingInterval = conf.getMessageCenterBgPoll() * 1000;
foregroundPollingInterval = conf.getMessageCenterFgPoll() * 1000;
ApptentiveLog.vv("Message Polling Worker: bg=%d, fg=%d", backgroundPollingInterval, foregroundPollingInterval);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class ApptentiveTaskManager implements PayloadStore, EventStore, Apptenti
private final ThreadPoolExecutor singleThreadExecutor; // TODO: replace with a private concurrent dispatch queue

private final PayloadSender payloadSender;
private boolean appInBackground;
private boolean appInBackground = true;

/*
* Creates an asynchronous task manager with one worker thread. This constructor must be invoked on the UI thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class Constants {

public static final int API_VERSION = 9;
public static final String APPTENTIVE_SDK_VERSION = "4.1.3";
public static final String APPTENTIVE_SDK_VERSION = "4.1.4";

public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 45000;
public static final int DEFAULT_READ_TIMEOUT_MILLIS = 45000;
Expand Down

0 comments on commit 2d62ae2

Please sign in to comment.