4

Is there a way to minimize the app to the background with a button inside the app?

Some apps do that when you press the exit option. They don't close but put the app in the background...

I want to do that with my Ionic app or with a cordova way.

tomloprod
  • 7,472
  • 6
  • 48
  • 66
LTroya
  • 530
  • 8
  • 23

3 Answers3

8

I just created a plugin called "AppMinimize" for cordova (only for Android devices) that does what you want. I hope it helps you.


Installation:

cordova plugin add https://github.com/tomloprod/cordova-plugin-appminimize.git

Usage:

window.plugins.appMinimize.minimize();

Ionic Example: Minimize app by pressing back button:

$ionicPlatform.registerBackButtonAction(function (event) {
    event.preventDefault();
    window.plugins.appMinimize.minimize();
}, 100);

Github:

https://github.com/tomloprod/cordova-plugin-appminimize

Community
  • 1
  • 1
tomloprod
  • 7,472
  • 6
  • 48
  • 66
0

if you are using ionic-3, solution from docs works like charm

  1. Install the Cordova and Ionic Native plugins:

    $ ionic cordova plugin add cordova-plugin-appminimize 
    
    $ npm install --save @ionic-native/app-minimize
    
  2. Add this plugin to your app's module

  3. Usage

    import { Platfrom } from 'ionic-angular';
    import { AppMinimize } from '@ionic-native/app-minimize';    
    
    constructor(private platform: Platform, private appMinimize: AppMinimize) { }
    
    ...
    
    this.platform.registerBackButtonAction(() => {
    this.appMinimize.minimize();
    });
    
Prashant
  • 1,375
  • 2
  • 14
  • 22
-3

You can do so using intent logic. Here is the android code you can find there

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

Let you do the rest to translate it in cordova/ionic ( don't know that framework)

Community
  • 1
  • 1
Bxtr
  • 316
  • 1
  • 13