Skip to content

Commit 107df99

Browse files
committed
[[ AndroidLaunchDataChanged ]] Add "launchDataChanged" message on Android
1 parent da284f2 commit 107df99

File tree

8 files changed

+174
-23
lines changed

8 files changed

+174
-23
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<doc>
2+
<legacy_id></legacy_id>
3+
<name>launchDataChanged</name>
4+
<type>message</type>
5+
<syntax>
6+
<example>launchDataChanged <i>launchData</i></example>
7+
</syntax>
8+
<synonyms>
9+
</synonyms>
10+
<references>
11+
<function tag="mobileGetLaunchData">mobileGetLaunchData Function</function>
12+
</references>
13+
<history>
14+
<introduced version="7.1">Added.</introduced>
15+
</history>
16+
<platforms>
17+
<android/>
18+
</platforms>
19+
<classes>
20+
<mobile/>
21+
</classes>
22+
<security>
23+
</security>
24+
<description>
25+
<overview>Sent to the <glossary tag="current card">current card</glossary> when the <glossary tag="application">application</glossary>'s launch data is changed by a new request from another app.</overview>
26+
<parameters>
27+
<parameter>
28+
<name>launchData</name>
29+
<description>The new request data in the form of an array.</description>
30+
</parameter>
31+
</parameters>
32+
33+
<comments>An Android app may be suspended in the background when it receives a request from another app. When this happens, the app's launch data is updated to contain the data for the new request and the app is resumed. This message allows the app to handle these new requests appropriately.</comments>
34+
</description>
35+
</doc>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# *launchDataChanged* message on Android
2+
3+
Added the *launchDataChanged* message on Android to indicate when the app was resumed to handle a new request from another app.

engine/src/java/com/runrev/android/Engine.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public class Engine extends View implements EngineApi
124124
// MM-2015-06-11: [[ MobileSockets ]] Trust manager and last verification error, used for verifying ssl certificates.
125125
private X509TrustManager m_trust_manager;
126126
private String m_last_certificate_verification_error;
127+
128+
private boolean m_new_intent;
127129

128130
////////////////////////////////////////////////////////////////////////////////
129131

@@ -213,6 +215,8 @@ public void onScreenOrientationChanged(int orientation)
213215
// work-around a general bug in android:
214216
// https://code.google.com/p/google-http-java-client/issues/detail?id=116
215217
System.setProperty("http.keepAlive", "false");
218+
219+
m_new_intent = false;
216220
}
217221

218222
////////////////////////////////////////////////////////////////////////////////
@@ -2870,12 +2874,27 @@ public void onResume()
28702874

28712875
doResume();
28722876

2877+
if (m_new_intent)
2878+
{
2879+
doLaunchDataChanged(getLaunchData());
2880+
2881+
String t_launch_url;
2882+
t_launch_url = getLaunchUri();
2883+
if (t_launch_url != null)
2884+
doLaunchFromUrl(t_launch_url);
2885+
2886+
m_new_intent = false;
2887+
}
2888+
28732889
s_running = true;
28742890
if (m_text_editor_visible)
28752891
showKeyboard();
28762892

28772893
// IM-2013-08-16: [[ Bugfix 11103 ]] dispatch any remote notifications received while paused
28782894
dispatchNotifications();
2895+
2896+
if (m_wake_on_event)
2897+
doProcess(false);
28792898
}
28802899

28812900
public void onDestroy()
@@ -2893,15 +2912,8 @@ public void onNewIntent(Intent intent)
28932912
{
28942913
// IM-2015-10-08: [[ Bug 15417 ]] Update the Intent of the Activity to the new one.
28952914
((Activity)getContext()).setIntent(intent);
2896-
2897-
String t_launch_url = getLaunchUri(intent);
2898-
if (t_launch_url != null)
2899-
{
2900-
doLaunchFromUrl(t_launch_url);
2901-
if (m_wake_on_event)
2902-
doProcess(false);
2903-
}
2904-
}
2915+
m_new_intent = true;
2916+
}
29052917

29062918
////////////////////////////////////////////////////////////////////////////////
29072919

@@ -3298,6 +3310,8 @@ private void onRunActivityResult(int p_result_code, Intent p_data)
32983310

32993311
// url launch callback
33003312
public static native void doLaunchFromUrl(String url);
3313+
// intent launch callback
3314+
public static native void doLaunchDataChanged(Map<String, Object> p_launch_data);
33013315

33023316
// callbacks from the billing service
33033317

engine/src/mblandroiddc.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4141
#include "mblandroidutil.h"
4242
#include "mblandroidjava.h"
4343

44+
#include "mblnotification.h"
45+
4446
#include "graphics.h"
4547
#include "resolution.h"
4648

@@ -2220,15 +2222,23 @@ JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doMediaCanceled(JNIEnv *en
22202222
MCAndroidMediaCanceled();
22212223
}
22222224

2223-
void MCNotificationPostUrlWakeUp(MCStringRef t_url);
2224-
22252225
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doLaunchFromUrl(JNIEnv *env, jobject object, jstring url) __attribute__((visibility("default")));
22262226
JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doLaunchFromUrl(JNIEnv *env, jobject object, jstring url)
22272227
{
22282228
MCAutoStringRef t_url_str;
22292229
if (MCJavaStringToStringRef(env, url, &t_url_str))
22302230
MCNotificationPostUrlWakeUp(*t_url_str);
22312231
}
2232+
2233+
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doLaunchDataChanged(JNIEnv *env, jobject object, jobject launch_data) __attribute__((visibility("default")));
2234+
JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doLaunchDataChanged(JNIEnv *env, jobject object, jobject launch_data)
2235+
{
2236+
2237+
MCAutoArrayRef t_array;
2238+
if (MCJavaMapToArrayRef(env, launch_data, &t_array))
2239+
/* UNCHECKED */ MCNotificationPostLaunchDataChanged(*t_array);
2240+
}
2241+
22322242
////////////////////////////////////////////////////////////////////////////////
22332243

22342244
static jmethodID s_get_asset_info_method = 0;

engine/src/mblnotification.cpp

Lines changed: 95 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3434
#include "mblsyntax.h"
3535
#include "mblnotification.h"
3636

37+
#include <stdarg.h>
38+
3739
////////////////////////////////////////////////////////////////////////////////
3840

3941
void FreeNotification(MCNotification &p_notification)
@@ -45,22 +47,34 @@ void FreeNotification(MCNotification &p_notification)
4547

4648
////////////////////////////////////////////////////////////////////////////////
4749

50+
static void MCParameterDeleteList(MCParameter *p_params)
51+
{
52+
while (p_params != nil)
53+
{
54+
MCParameter *t_param;
55+
t_param = p_params;
56+
p_params = p_params->getnext();
57+
delete t_param;
58+
}
59+
}
60+
4861
class MCNotificationEvent: public MCCustomEvent
4962
{
5063
private:
5164
MCNameRef m_message;
52-
MCStringRef m_notification;
53-
65+
MCParameter *m_params;
66+
5467
public:
55-
MCNotificationEvent (MCNameRef p_message, MCStringRef p_notification)
68+
MCNotificationEvent (MCNameRef p_message, MCParameter *p_params)
5669
{
57-
m_message = p_message;
58-
m_notification = MCValueRetain(p_notification);
70+
m_message = MCValueRetain(p_message);
71+
m_params = p_params;
5972
}
6073

6174
~MCNotificationEvent()
6275
{
63-
MCValueRelease(m_notification);
76+
MCValueRelease(m_message);
77+
MCParameterDeleteList(m_params);
6478
}
6579

6680
void Destroy(void)
@@ -70,31 +84,100 @@ class MCNotificationEvent: public MCCustomEvent
7084

7185
void Dispatch(void)
7286
{
73-
MCdefaultstackptr -> getcurcard() -> message_with_valueref_args (m_message, m_notification);
87+
MCdefaultstackptr -> getcurcard() -> message(m_message, m_params);
7488
}
7589
};
7690

91+
bool MCNotificationPostCustom(MCNameRef p_name, uint32_t p_param_count, ...)
92+
{
93+
bool t_success;
94+
t_success = true;
95+
96+
MCParameter *t_param_list;
97+
t_param_list = nil;
98+
99+
MCParameter *t_param;
100+
t_param = nil;
101+
102+
va_list t_args;
103+
va_start(t_args, p_param_count);
104+
105+
for (uint32_t i = 0; t_success && i < p_param_count; i++)
106+
{
107+
MCValueRef t_value;
108+
t_value = va_arg(t_args, MCValueRef);
109+
110+
MCParameter *t_new_param;
111+
t_new_param = new MCParameter();
112+
t_success = t_new_param != nil;
113+
114+
if (t_success)
115+
{
116+
t_new_param->setvalueref_argument(t_value);
117+
if (t_param != nil)
118+
t_param->setnext(t_new_param);
119+
t_param = t_new_param;
120+
121+
if (t_param_list == nil)
122+
t_param_list = t_param;
123+
}
124+
}
125+
126+
va_end(t_args);
127+
128+
MCNotificationEvent *t_event;
129+
t_event = nil;
130+
131+
if (t_success)
132+
{
133+
t_event = new MCNotificationEvent(p_name, t_param_list);
134+
t_success = t_event != nil;
135+
}
136+
137+
if (t_success)
138+
t_success = MCEventQueuePostCustom(t_event);
139+
140+
if (!t_success)
141+
{
142+
if (t_event != nil)
143+
delete t_event;
144+
else
145+
MCParameterDeleteList(t_param_list);
146+
}
147+
148+
return t_success;
149+
}
150+
151+
////////////////////////////////////////////////////////////////////////////////
152+
77153
void MCNotificationPostLocalNotificationEvent(MCStringRef p_payload)
78154
{
79-
MCEventQueuePostCustom(new MCNotificationEvent(MCM_local_notification_received, p_payload));
155+
/* UNCHECKED */ MCNotificationPostCustom(MCM_local_notification_received, 1, p_payload);
80156
}
81157

82158
void MCNotificationPostPushNotificationEvent(MCStringRef p_payload)
83159
{
84-
MCEventQueuePostCustom(new MCNotificationEvent (MCM_push_notification_received, p_payload));
160+
/* UNCHECKED */ MCNotificationPostCustom(MCM_push_notification_received, 1, p_payload);
85161
}
86162

87163
void MCNotificationPostPushRegistered (MCStringRef p_registration_text)
88164
{
89-
MCEventQueuePostCustom(new MCNotificationEvent (MCM_push_notification_registered, p_registration_text));
165+
/* UNCHECKED */ MCNotificationPostCustom(MCM_push_notification_registered, 1, p_registration_text);
90166
}
91167

92168
void MCNotificationPostPushRegistrationError (MCStringRef p_error_text)
93169
{
94-
MCEventQueuePostCustom(new MCNotificationEvent (MCM_push_notification_registration_error, p_error_text));
170+
/* UNCHECKED */ MCNotificationPostCustom(MCM_push_notification_registration_error, 1, p_error_text);
95171
}
96172

97173
void MCNotificationPostUrlWakeUp (MCStringRef p_url_wake_up_text)
98174
{
99-
MCEventQueuePostCustom(new MCNotificationEvent (MCM_url_wake_up, p_url_wake_up_text));
175+
/* UNCHECKED */ MCNotificationPostCustom(MCM_url_wake_up, 1, p_url_wake_up_text);
176+
}
177+
178+
void MCNotificationPostLaunchDataChanged(MCArrayRef p_launch_data)
179+
{
180+
/* UNCHECKED */ MCNotificationPostCustom(MCM_launch_data_changed, 1, p_launch_data);
100181
}
182+
183+
////////////////////////////////////////////////////////////////////////////////

engine/src/mblnotification.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ void MCNotificationPostPushNotificationEvent(MCStringRef p_payload);
2424
void MCNotificationPostPushRegistered (MCStringRef p_registration_text);
2525
void MCNotificationPostPushRegistrationError (MCStringRef p_error_text);
2626
void MCNotificationPostUrlWakeUp (MCStringRef p_url_wake_up_text);
27+
void MCNotificationPostLaunchDataChanged(MCArrayRef p_data);
28+
bool MCNotificationPostCustom(MCNameRef p_message, uint32_t p_param_count, ...);
2729

2830
#endif

engine/src/mcstring.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ MCNameRef MCM_push_notification_received;
564564
MCNameRef MCM_push_notification_registered;
565565
MCNameRef MCM_push_notification_registration_error;
566566
MCNameRef MCM_url_wake_up;
567+
MCNameRef MCM_launch_data_changed;
567568
MCNameRef MCM_browser_started_loading;
568569
MCNameRef MCM_browser_finished_loading;
569570
MCNameRef MCM_browser_load_failed;
@@ -1006,6 +1007,7 @@ void MCU_initialize_names(void)
10061007
/* UNCHECKED */ MCNameCreateWithCString("pushNotificationRegistered", MCM_push_notification_registered);
10071008
/* UNCHECKED */ MCNameCreateWithCString("pushNotificationRegistrationError", MCM_push_notification_registration_error);
10081009
/* UNCHECKED */ MCNameCreateWithCString("urlWakeUp", MCM_url_wake_up);
1010+
/* UNCHECKED */ MCNameCreateWithCString("launchDataChanged", MCM_launch_data_changed);
10091011
/* UNCHECKED */ MCNameCreateWithCString("browserStartedLoading", MCM_browser_started_loading);
10101012
/* UNCHECKED */ MCNameCreateWithCString("browserFinishedLoading", MCM_browser_finished_loading);
10111013
/* UNCHECKED */ MCNameCreateWithCString("browserLoadFailed", MCM_browser_load_failed);
@@ -1440,6 +1442,7 @@ void MCU_finalize_names(void)
14401442
MCNameDelete(MCM_push_notification_registered);
14411443
MCNameDelete(MCM_push_notification_registration_error);
14421444
MCNameDelete(MCM_url_wake_up);
1445+
MCNameDelete(MCM_launch_data_changed);
14431446
MCNameDelete(MCM_browser_started_loading);
14441447
MCNameDelete(MCM_browser_finished_loading);
14451448
MCNameDelete(MCM_browser_load_failed);

engine/src/mcstring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ extern MCNameRef MCM_push_notification_received;
537537
extern MCNameRef MCM_push_notification_registered;
538538
extern MCNameRef MCM_push_notification_registration_error;
539539
extern MCNameRef MCM_url_wake_up;
540+
extern MCNameRef MCM_launch_data_changed;
540541

541542
extern MCNameRef MCM_browser_started_loading;
542543
extern MCNameRef MCM_browser_finished_loading;

0 commit comments

Comments
 (0)