# How to show up a modal on phone when the user is not viewing the app?

**URL:** <https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809>\
**Category:** ionic-v1\
**Created:** [December 28, 2014, 10:27pm UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809 "2014-12-28T22:27:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![amsonline](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@amsonline](https://forum.ionicframework.com/u/amsonline)\
**Post date:** [December 28, 2014, 10:27pm UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/1 "2014-12-28T22:27:21Z")

</div>

Hello  
I am writing an small messaging app for my employees. This app works with Node.js server. Everything is ok, except this feature:

I want to turn the screen on and show up the message inside a modal when an employee receives it, even when he/she is not viewing the app, even when his/her phone is locked? Does Ionic Popup/Modal service do it for me? This feature I want to implement is like Android’s Messaging app or Viber.

I didn’t find anything over the net.

Any help is appreciated

---

<div class="post-metadata">

**Author:** ![harshitgoel96](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@harshitgoel96](https://forum.ionicframework.com/u/harshitgoel96)\
**Post date:** [December 29, 2014, 7:34am UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/2 "2014-12-29T07:34:36Z")

</div>

Modal can be only displayed within app… what you might be looking for is a notification…  
have a look at push notification and Google Cloud messagein

[https://developer.android.com/google/gcm/index.html](https://developer.android.com/google/gcm/index.html)

---

<div class="post-metadata">

**Author:** ![jimibi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jimibi/32/7945_2.png) [@jimibi](https://forum.ionicframework.com/u/jimibi)\
**Post date:** [December 29, 2014, 9:55am UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/3 "2014-12-29T09:55:26Z")

</div>

You can test my plugin (fork of [https://github.com/Viras-/cordova-plugin-powermanagement](https://github.com/Viras-/cordova-plugin-powermanagement)) : [https://github.com/jimibi/cordova-plugin-powermanagement](https://github.com/jimibi/cordova-plugin-powermanagement).  
It must solve a lot of your problems.

---

<div class="post-metadata">

**Author:** ![amsonline](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@amsonline](https://forum.ionicframework.com/u/amsonline)\
**Post date:** [December 29, 2014, 10:01am UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/4 "2014-12-29T10:01:42Z")

</div>

@harshitgoel96 my app has push notifications, I want a box show up in the users’ screen, showing the preview of the message, a text box to reply and some buttons to close the box or view the message in app. I don’t know how to bring it up.

---

<div class="post-metadata">

**Author:** ![amsonline](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@amsonline](https://forum.ionicframework.com/u/amsonline)\
**Post date:** [December 29, 2014, 10:07am UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/5 "2014-12-29T10:07:36Z")

</div>

Thanks, this plugin helps me to turn the screen on, but I didn’t find any way to show up the message box on the screen, yet.

---

<div class="post-metadata">

**Author:** ![harshitgoel96](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@harshitgoel96](https://forum.ionicframework.com/u/harshitgoel96)\
**Post date:** [December 29, 2014, 10:23am UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/6 "2014-12-29T10:23:09Z")

</div>

i just checked the plugin… if the alert box is shown without the app being active, then in the same place load a custom modal…

```
  sucAlert = function() {
        alert('Success');

//place model here
//$ionicModal.fromTemplate();
    };
    errAlert = function() {
        alert('Error');
    };
    powerManagement.acquire(sucAlert, errAlert); // awake the smartphone
    powerManagement.release(sucAlert, errAlert); // allowed to sleep again
```

---

<div class="post-metadata">

**Author:** ![jimibi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jimibi/32/7945_2.png) [@jimibi](https://forum.ionicframework.com/u/jimibi)\
**Post date:** [December 29, 2014, 10:24am UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/7 "2014-12-29T10:24:10Z")

</div>

Uses callBack function, like this:

> ```
> sucFunction = function () {
> //Modal call
> },
> errAlert = function () {
> alert('Error');
> },
> sucAlert = function () {
> toForeground('StarterApp', 'com.ionicframework.starter', sucFunction, errAlert);
> };
> powerManagement.acquire(sucAlert, errAlert);
> powerManagement.release(sucFunction, errAlert);
> 
> ```

---

<div class="post-metadata">

**Author:** ![harshitgoel96](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@harshitgoel96](https://forum.ionicframework.com/u/harshitgoel96)\
**Post date:** [December 29, 2014, 10:25am UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/8 "2014-12-29T10:25:26Z")

</div>

just a query… would your plugin be working when the app is closed ??

**EDIT** and what does toForeground does ??? where can i look for it ?

---

<div class="post-metadata">

**Author:** ![jimibi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jimibi/32/7945_2.png) [@jimibi](https://forum.ionicframework.com/u/jimibi)\
**Post date:** [December 29, 2014, 10:28am UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/9 "2014-12-29T10:28:21Z")

</div>

No, the application must be in background or in foreground

---

<div class="post-metadata">

**Author:** ![jimibi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jimibi/32/7945_2.png) [@jimibi](https://forum.ionicframework.com/u/jimibi)\
**Post date:** [December 29, 2014, 10:32am UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/10 "2014-12-29T10:32:05Z")

</div>

A plugin for codova, which will allow the app to bring itself, or other app activites, to the foreground.

Fork this plugin: [https://github.com/jimibi/cordova-toforeground](https://github.com/jimibi/cordova-toforeground)

---

<div class="post-metadata">

**Author:** ![rafaellop](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@rafaellop](https://forum.ionicframework.com/u/rafaellop)\
**Post date:** [December 29, 2014, 7:12pm UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/11 "2014-12-29T19:12:26Z")

</div>

@jimibi tell me please if it is possible with your plugin on Android to keep an application (cordova/phonegap) in memory and active? I’ve noticed that even if I use wake lock (not from your plugin), my app is getting less and less active and finally it is stopped by the system. The app is supposed to do a task each minute. At the beginning it works correctly and then the period between calling the timer is getting longer and finally the app is stopped. If I connect external power source it works correctly, but on battery Android is lulling it and I cannot do anything to prevent this. Is anything (without external service) possible to achieve this functionality of keeping an app active and do some task each minute forever?

---

<div class="post-metadata">

**Author:** ![jimibi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jimibi/32/7945_2.png) [@jimibi](https://forum.ionicframework.com/u/jimibi)\
**Post date:** [December 29, 2014, 9:45pm UTC](https://forum.ionicframework.com/t/how-to-show-up-a-modal-on-phone-when-the-user-is-not-viewing-the-app/14809/13 "2014-12-29T21:45:19Z")

</div>

No, for this use: [https://github.com/katzer/cordova-plugin-background-mode](https://github.com/katzer/cordova-plugin-background-mode)
