How do I wake up another App before exiting the App ?, Quit the app and wake up another

Source: Internet
Author: User

How do I wake up another App before exiting the App ?, Quit the app and wake up another

Master haomeng is devoted to his contribution and respects the author's Labor achievements. Do not repost them.

If the article is helpful to you, you are welcome to donate to the author, support haomeng master, the amount of donation is free, focusing on your mind ^_^

I want to donate: Click to donate

Cocos2d-X source code download: point I send


The SDK does not provide a method to terminate the application.

To terminate an application, the only method recommended by Apple is to press the Home button.


However, the Foundation framework integrates the Darwin framework, so that we can use the C function exit (0) to terminate the Application.

 

The openUrl method of UIApplication is another way to exit the application.

When you call the OpenURL method in the code, your App process is terminated (suspended), and the other App is awakened.

 

Of course, the two withdrawal mechanisms and the final effect are not the same.

When you exit the program using exit (0), your App does not only exit the foreground, but also clears the memory occupied by the Program-this is irrecoverable.

If the App is Launch again, iOS will read the binary from the disk again-this is a brand new App Image.

 

OpenURL is different. It only suspends your program, which is recoverable.

Your App only exits from the foreground, but the background still exists.

You can "wake up" it at some time, so your App is back, and the application status is still awake.

Of course, if you are not lucky, iOS will also completely recycle your App from the memory,

As with exit (0), This is generally the case when the system memory is tight.

 

These two methods may coexist in some cases.

For example, we want to wake up another App, such as Safari, before the App exits.

At the same time, we want our App to "Exit" and reclaim all the App memory.


This is a "Paradox ". Because no matter whether exit (0) or openURL, once executed, the operating system will terminate the process execution.

If you execute either of the statements, the other statement cannot be executed-because the process has been terminated.

 

However, in some cases, through the clever use of the iOS multitasking mechanism, this paradox is true.

For example, we can use the following O-C code to achieve this:

 

[Self defined mselector: @ selector (exitApp) withObject: nil afterDelay: 0.5];

[[UIApplication sharedApplication] openURL:

[NSURLURLWithString: @ "appScheme: //"];

 

The exitApp method is actually a Code such as exit (0 ).

In this way, the two will coexist.


First, let's delay exit (0) by 0.5 seconds and then execute it. Before that, of course, openURL has already been executed.

PerformSelector: The afterDelay method schedules a task to be executed after a certain time.

Of course, this time cannot be too long ,].

Because iOS allows the app to remain "alive" for a period of time after entering the background, but this time cannot be too long,

In this way, after the openURL method is executed, the App is still alive and has the opportunity to execute the scheduled task (exit (0 )).


Master haomeng is devoted to his contribution and respects the author's Labor achievements. Do not repost them.

If the article is helpful to you, you are welcome to donate to the author, support haomeng master, the amount of donation is free, focusing on your mind ^_^

I want to donate: Click to donate

Cocos2d-X source code download: point I send

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.