Skip to content

Commit 11c22cd

Browse files
author
Morten Brix Pedersen
committed
Fix Android 6 crash.
It is now required to pass Activity to the run() method to make sure the Activity is still there when starting the queue page, in the scenario where applications are storing the QueueITEngine for longer periods. Closes #4
1 parent 641312d commit 11c22cd

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Invoke QueueITEngine as per example below. Parameters `layoutName` and `language
3737
});
3838

3939
try {
40-
engine.run();
40+
engine.run(YourActivity.this);
4141
}
4242
catch (QueueITException e) { } // Gets thrown when a request is already in progress.
4343

demoapp/src/main/java/com/queue_it/shopdemo/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void onError(Error error, String errorMessage) {
108108
}
109109
});
110110
try {
111-
queueITEngine.run(!enableCacheRadioButton.isChecked());
111+
queueITEngine.run(MainActivity.this, !enableCacheRadioButton.isChecked());
112112
}
113113
catch (QueueITException e) {
114114
Toast.makeText(getApplicationContext(), "Please try again.", Toast.LENGTH_LONG).show();

library/src/main/java/com/queue_it/androidsdk/QueueITEngine.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class QueueITEngine {
2626
private QueueCache _queueCache;
2727
private Context _context;
2828

29+
private Activity _activity;
2930
private boolean _requestInProgress;
3031
private boolean _isInQueue;
3132

@@ -38,12 +39,12 @@ public class QueueITEngine {
3839
private Handler _checkConnectionHandler;
3940
private int _isOnlineRetry = 0;
4041

41-
public QueueITEngine(Activity activity, String customerId, String eventOrAliasId, QueueListener queueListener)
42+
public QueueITEngine(Context applicationContext, String customerId, String eventOrAliasId, QueueListener queueListener)
4243
{
43-
this(activity, customerId, eventOrAliasId, "", "", queueListener);
44+
this(applicationContext, customerId, eventOrAliasId, "", "", queueListener);
4445
}
4546

46-
public QueueITEngine(Activity activity, String customerId, String eventOrAliasId, String layoutName,
47+
public QueueITEngine(Context applicationContext, String customerId, String eventOrAliasId, String layoutName,
4748
String language, QueueListener queueListener)
4849
{
4950
if (TextUtils.isEmpty(customerId))
@@ -54,13 +55,13 @@ public QueueITEngine(Activity activity, String customerId, String eventOrAliasId
5455
{
5556
throw new IllegalArgumentException("eventOrAliasId must have a value");
5657
}
57-
_context = activity.getApplicationContext();
58+
_context = applicationContext.getApplicationContext();
5859
_customerId = customerId;
5960
_eventOrAliasId = eventOrAliasId;
6061
_layoutName = layoutName;
6162
_language = language;
6263
_queueListener = queueListener;
63-
_queueCache = new QueueCache(activity, customerId, eventOrAliasId);
64+
_queueCache = new QueueCache(_context, customerId, eventOrAliasId);
6465
_deltaSec = INITIAL_WAIT_RETRY_SEC;
6566
}
6667

@@ -86,17 +87,18 @@ private boolean isOnline() {
8687
return netInfo != null && netInfo.isConnected();
8788
}
8889

89-
public void run(boolean clearCache) throws QueueITException
90+
public void run(Activity activity, boolean clearCache) throws QueueITException
9091
{
9192
if (clearCache)
9293
{
9394
_queueCache.clear();
9495
}
95-
run();
96+
run(activity);
9697
}
9798

98-
public void run() throws QueueITException
99+
public void run(Activity activity) throws QueueITException
99100
{
101+
_activity = activity;
100102
registerReceivers();
101103

102104
if (_requestInProgress)
@@ -189,7 +191,7 @@ private void showQueue(String queueUrl, final String targetUrl)
189191
Intent intent = new Intent(_context, QueueActivity.class);
190192
intent.putExtra("queueUrl", queueUrl);
191193
intent.putExtra("targetUrl", targetUrl);
192-
_context.startActivity(intent);
194+
_activity.startActivity(intent);
193195
}
194196

195197
private void raiseQueueViewWillOpen()

0 commit comments

Comments
 (0)