Skip to content

Commit cbf93ac

Browse files
authored
Merge pull request #3543 from dimagi/hotfix_fix-login-redirect-crash-from-non-activity-context
[Hotfix] Fix login redirection issues
2 parents 305c514 + 82bbaba commit cbf93ac

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

app/src/org/commcare/CommCareApplication.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ public void expireUserSession() {
415415
synchronized (serviceLock) {
416416
closeUserSession();
417417
SessionRegistrationHelper.registerSessionExpiration();
418-
sendBroadcast(new Intent(SessionRegistrationHelper.USER_SESSION_EXPIRED));
418+
sendBroadcast(
419+
new Intent(SessionRegistrationHelper.USER_SESSION_EXPIRED)
420+
.setPackage(this.getPackageName())
421+
);
419422
}
420423
}
421424

app/src/org/commcare/utils/SessionRegistrationHelper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.commcare.utils;
22

3+
import android.app.Activity;
34
import android.content.BroadcastReceiver;
45
import android.content.Context;
56
import android.content.Intent;
@@ -98,7 +99,10 @@ public static void unregisterSessionExpiration() {
9899
*/
99100
public static void redirectToLogin(Context context) {
100101
Intent i = new Intent(context.getApplicationContext(), DispatchActivity.class);
101-
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
102+
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
103+
if (!(context instanceof Activity)) {
104+
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
105+
}
102106
context.startActivity(i);
103107
}
104108
}

0 commit comments

Comments
 (0)