After exit via Hardware back button, Device plugin not installed?

Hello, I am currently building app using ionic2.

Basically, on app init, it will send request to http server to check whether device has been registered on my database or not, if server return true it will redirect to login page, otherwise go to either registration or wait for activation page.

On first run or after force kill app (using task manager), this works as it should be. However, when I exit the app via hardware back button, app init not working as it should be, it will always redirect to wait for activation page instead.

i found some of this error on adb log

06-10 03:26:52.904: I/chromium(10056): [INFO:CONSOLE(74905)] "Native: tried calling Device.device, but the Device plugin is not installed.", source: file:///android_asset/www/build/js/app.bundle.js (74905)
06-10 03:26:52.904: I/chromium(10056): [INFO:CONSOLE(74910)] "Install the Device plugin: 'cordova plugin add cordova-plugin-device'", source: file:///android_asset/www/build/js/app.bundle.js (74910)
06-10 03:26:52.905: I/chromium(10056): [INFO:CONSOLE(74905)] "Native: tried calling Device.device, but the Device plugin is not installed.", source: file:///android_asset/www/build/js/app.bundle.js (74905)
06-10 03:26:52.906: I/chromium(10056): [INFO:CONSOLE(74910)] "Install the Device plugin: 'cordova plugin add cordova-plugin-device'", source: file:///android_asset/www/build/js/app.bundle.js (74910)
06-10 03:26:53.161: I/chromium(10056): [INFO:CONSOLE(69183)] "Native: deviceready did not fire within 2000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.", source: file:///android_asset/www/build/js/app.bundle.js (69183)

I try to reinstall plugin already but still got same behaviour.
I have put my http request code under this.platform.ready().then{ ... } block.

Note: same behaviour before and after trying to handle hardware back button as mentioned in this page

has anyone face this problem? How to make app certainly wait for plugin availability after suspend(?)?

Ionic Info : 
Cordova CLI: 6.2.0
Ionic Framework Version: 2.0.0-beta.7
Ionic CLI Version: 2.0.0-beta.25
Ionic App Lib Version: 2.0.0-beta.15
OS: Distributor ID:	Ubuntu Description:	Ubuntu 16.04 LTS 
Node Version: v4.4.5

Are you doing this after platform.ready?

@mhartington yeah the block code which calling http request i meant is inside platform ready code. i already try to move code block to first page callled on app.ts (e.g on LoginPage.ts) inside viewDidEnter but still got same behaviour. I am moving it back to app.ts initializeApp block and handle my hardware back button so app is uncloseable via back button to avoid this behaviour

@mhartington I try to retest this on newly created app after updating ionic to latest version (Beta.8).

  • ionic start test-app --v2 --ts

  • Add this line code to home-page.ts constructor
    platform.ready().then(()=> this.myUUID = Device.device.uuid);

surprisingly it went well, the app indeed waits for platform to be ready first.
I will try to update ionic version on my app and see if updating solve this.

Note :
On latest version, I notice ionicBootstrap(MyApp) code on last line of app.ts. What’s the function of this line since older version didn’t have it?

Thanks

I got the culprit.

The problem caused because I made http calls through separate TS service file.

platform.ready().then(() =>
{
      this.edcSvc.cekRegistered(...)
}

while in edcService.ts I didn’t import platform and put cordova related code inside platform.ready() code

simply add that code block

import {Platform} from 'ionic-angular'
import {Device} from 'ionic-native'
...
   platform.ready().then(()=>
   {  
      this.uuid = Device.device.uuid;
   });

solves all problem.
Tested on both beta.7 and beta.8 project

When I call service code inside platform.ready() on app.ts I assume that code being called after platform “really ready”. Apparently it is not the case and I have to put platform.ready() also on my Service file.