Programmatically Sending an App to Background

Programmatically sending an app to background

I would recommend checking out XCUIDevice. Here is how you might press the home button and then relaunch the application

func testExample() {

// Has a nav bar.
XCTAssert(XCUIApplication().navigationBars.element.exists)

XCUIDevice().press(XCUIDeviceButton.home)
// Before Swift 3: XCUIDevice().pressButton(XCUIDeviceButton.Home)
XCUIApplication().launch()

// Navigationbar still there on second launch.
XCTAssert(XCUIApplication().navigationBars.element.exists)
}

Is there any way to programmatically send my iPhone app to the background

Already answered quite well here:

Suspend the application

As that poster wrote:

Quitting your application or sending it to the background programmatically is a violation of the [iOS Human Interface Guidelines][1], which usually doesn't bode well for getting through the review process:

Don’t Quit Programmatically

Never quit an iOS application
programmatically because people tend
to interpret this as a crash. However,
if external circumstances prevent your
application from functioning as
intended, you need to tell your users
about the situation and explain what
they can do about it. Depending on how
severe the application malfunction is,
you have two choices.

Display an attractive screen that describes the problem and suggests a
correction.
A screen provides
feedback that reassures users that
there’s nothing wrong with your
application. It puts users in control,
letting them decide whether they want
to take corrective action and continue
using your application or press the
Home button and open a different
application

If only some of your application's features are not working, display
either a screen or an alert when
people activate the feature.
Display
the alert only when people try to
access the feature that isn’t
functioning.

Sending a running application to background programmatically

Maybe play the sound from a service instead?

Send App to Background process

Not possible. Home button clicks run into the private GSEvents framework. It's exit() or none unfortunately.

Ways to bring an Android app in background to foreground

In MyMainActivity definition (AndroidManifest.xml):

<intent-filter>
<action android:name="intent.my.action" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Programmatically bringing application to foreground:

Intent it = new Intent("intent.my.action");
it.setComponent(new ComponentName(context.getPackageName(), MyMainActivity.class.getName()));
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(it);

Note: context.startActivity(it) would NOT work when the context object is same as the activity one wants to bring up.

How to remove app from background programmatically in ios

A solution is to send a silent notification and upon getting the notification calling exit(0) in you code but I will recommend against this as it will not pass Apple review.

Send Android app to background with Firemonkey

This code should do what you want:

uses
Androidapi.Helpers, Androidapi.JNI.GraphicsContentViewText;

procedure SendAppToBackground;
var
LIntent: JIntent;
begin
LIntent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_MAIN);
LIntent.addCategory(TJIntent.JavaClass.CATEGORY_HOME);
LIntent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
TAndroidHelper.Context.startActivity(LIntent);
end;

Based on this answer.

EDIT:

My memory is defective because I came up with this 2 years ago:

uses
Androidapi.Helpers;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
if key = vkHardwareBack then
begin
Key := 0;
TAndroidHelper.Activity.moveTaskToBack(True);
end;
end;

Having said that, this solution might not go to the Home screen



Related Topics



Leave a reply



Submit