hazemhagrass / phonegap-background

37 stars 12 forks source link

Ionic background mode doesn't work well in my ionic application #10

Open n1705771 opened 5 years ago

n1705771 commented 5 years ago

I want my ionic app can continue send message to the server even though the phone screen turn off or enter the background mode. To achieve this, I apply ionic native background mode as:

  //background mode enable
  this.backgroundMode.enable();

  //When background mode is activated
  this.backgroundMode.on("activate").subscribe(()=>{
    console.log("activate background mode");

    //clear intervalId 
    clearInterval(this.intervalId); 

    //set interval for sending message every 10 seconds
    this.intervalId = setInterval(() => {this.sendMessage()}, 10000); 
  });

  clearInterval(this.intervalId);
  this.intervalId = setInterval(() => {this.sendMessage()}, 10000);

When I run the program in my Android phone, it just works properly for exact 5 minutes in background mode, then stop sending the messages.

Can you explain why background mode doesn't works well? How can I solve this problem?