Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: On mobile App status changes.



Permlink Replies: 6 - Last Post: Jun 9, 2014 3:41 PM Last Post By: Haizhou Tang
Haizhou Tang

Posts: 17
Registered: 2/12/06
On mobile App status changes.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2014 12:14 PM
When developing mobile by XE6, how to trigger event when app being set to background?
and reverse side event when same app brought back to front end? Tried both onDeavtivate and OnActivate,
none of them working in iOS app.
How to catch the application event and catch the app status changes?

Also, in iOS , when app sent back to background by clicking home button , some things different happened compared to device goes to sleep/lock mode.
Anyway to differiciate that two events ?
Eli M

Posts: 1,346
Registered: 11/9/13
Re: On mobile App status changes.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2014 11:33 PM   in response to: Haizhou Tang in response to: Haizhou Tang
Haizhou Tang

Posts: 17
Registered: 2/12/06
Re: On mobile App status changes.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 2, 2014 2:46 PM   in response to: Eli M in response to: Eli M

Thanks Eli for this link. However, the sample code is not working properly.
Keep complaining all the aeFinishedLaunching etc. undeclared. I know from Jeff's comments and trace back to source.
the ae has been removed in XE6, so modified the code accordingly

FinishedLaunching: Log('Finished Launching');
BecameActive: Log('Became Active');
WillBecomeInactive: Log('Will Become Inactive');
EnteredBackground: Log('Entered Background');
WillBecomeForeground: Log('Will Become Foreground');
but still got the same error message:
[DCC Error] Unit11.pas(44): E2003 Undeclared identifier: 'FinishedLaunching'
Any Idea?
John Frazier


Posts: 726
Registered: 2/17/00
Re: On mobile App status changes.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 5, 2014 5:27 PM   in response to: Haizhou Tang in response to: Haizhou Tang
Haizhou Tang wrote:

Thanks Eli for this link. However, the sample code is not working properly.
Keep complaining all the aeFinishedLaunching etc. undeclared. I know from Jeff's comments and trace back to source.
the ae has been removed in XE6, so modified the code accordingly

I didn't know until a few moments ago. No they have not been removed, just rescoped as of XE6. Instead of the following...

function TForm11.HandleAppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
begin
case AAppEvent of
aeFinishedLaunching: Log('Finished Launching');
aeBecameActive: Log('Became Active');
aeWillBecomeInactive: Log('Will Become Inactive');
aeEnteredBackground: Log('Entered Background');
aeWillBecomeForeground: Log('Will Become Foreground');
aeWillTerminate: Log('Will Terminate');
aeLowMemory: Log('Low Memory');
aeTimeChange: Log('Time Change');
aeOpenURL: Log('Open URL');
end;
Result := True;
end;

...change to this and it works great...

function TForm11.HandleAppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
begin
case AAppEvent of
TApplicationEvent.aeFinishedLaunching: Log('Finished Launching');
TApplicationEvent.aeBecameActive: Log('Became Active');
TApplicationEvent.aeWillBecomeInactive: Log('Will Become Inactive');
TApplicationEvent.aeEnteredBackground: Log('Entered Background');
TApplicationEvent.aeWillBecomeForeground: Log('Will Become Foreground');
TApplicationEvent.aeWillTerminate: Log('Will Terminate');
TApplicationEvent.aeLowMemory: Log('Low Memory');
TApplicationEvent.aeTimeChange: Log('Time Change');
TApplicationEvent.aeOpenURL: Log('Open URL');
end;
Result := True;
end;

**I posted update to Pawel's blog comments too. :)
--
John Frazier (Embarcadero Newsgroup Admin)

Haizhou Tang

Posts: 17
Registered: 2/12/06
Re: On mobile App status changes.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 6, 2014 7:54 AM   in response to: John Frazier in response to: John Frazier
You are a start, solved a very fundamental issue.

Although I am not quite sure what the rescope means, but in my mind,
it seems TApplicationEvent is a class. Use a TApplicationEvent.aeFinishedLaunching
means use a class property rather than the instance of the class AAppEvent just made me puzzled.
If you can enlighten me about this , it will be great.

It indeed work after adding the prefix. However, that sample code can only detect
3 App events,
TApplicationEvent.aeBecameActive: Log('Became Active');
TApplicationEvent.aeEnteredBackground: Log('Entered Background');
TApplicationEvent.aeWillBecomeForeground: Log('Will Become Foreground');

Can not be trigger for these two.
TApplicationEvent.aeFinishedLaunching: Log('Finished Launching');
TApplicationEvent.aeWillBecomeInactive: Log('Will Become Inactive');

In fact, WillBecomeInactive is rather important, I need to do sth , like saving data, disconnect networks, etc when this one is triggered.
Any idea?

thanks

John Frazier wrote:
Haizhou Tang wrote:

Thanks Eli for this link. However, the sample code is not working properly.
Keep complaining all the aeFinishedLaunching etc. undeclared. I know from Jeff's comments and trace back to source.
the ae has been removed in XE6, so modified the code accordingly

I didn't know until a few moments ago. No they have not been removed, just rescoped as of XE6. Instead of the following...

function TForm11.HandleAppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
begin
case AAppEvent of
aeFinishedLaunching: Log('Finished Launching');
aeBecameActive: Log('Became Active');
aeWillBecomeInactive: Log('Will Become Inactive');
aeEnteredBackground: Log('Entered Background');
aeWillBecomeForeground: Log('Will Become Foreground');
aeWillTerminate: Log('Will Terminate');
aeLowMemory: Log('Low Memory');
aeTimeChange: Log('Time Change');
aeOpenURL: Log('Open URL');
end;
Result := True;
end;

...change to this and it works great...

function TForm11.HandleAppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
begin
case AAppEvent of
TApplicationEvent.aeFinishedLaunching: Log('Finished Launching');
TApplicationEvent.aeBecameActive: Log('Became Active');
TApplicationEvent.aeWillBecomeInactive: Log('Will Become Inactive');
TApplicationEvent.aeEnteredBackground: Log('Entered Background');
TApplicationEvent.aeWillBecomeForeground: Log('Will Become Foreground');
TApplicationEvent.aeWillTerminate: Log('Will Terminate');
TApplicationEvent.aeLowMemory: Log('Low Memory');
TApplicationEvent.aeTimeChange: Log('Time Change');
TApplicationEvent.aeOpenURL: Log('Open URL');
end;
Result := True;
end;

**I posted update to Pawel's blog comments too. :)
--
John Frazier (Embarcadero Newsgroup Admin)

Douglas Rudd

Posts: 314
Registered: 5/16/97
Re: On mobile App status changes.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 9, 2014 3:36 PM   in response to: Haizhou Tang in response to: Haizhou Tang
TApplicationEvent is just a type name for a set of integers.

You can use TApplicationEvent.aeWillTerminate for doing what you want to do before the app quits.
Haizhou Tang

Posts: 17
Registered: 2/12/06
Re: On mobile App status changes.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 9, 2014 3:41 PM   in response to: Douglas Rudd in response to: Douglas Rudd
Thanks Douglas, it explains it. Do you have any idea why only three status can be triggered?
This seems rather difficult to track/debug.

Douglas Rudd wrote:
TApplicationEvent is just a type name for a set of integers.

You can use TApplicationEvent.aeWillTerminate for doing what you want to do before the app quits.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02