-1

Is it possible to start an app in the background? For example, if a push notification is received, then the app is started in the background,without invoking the UI/screen?

Because at the moment i have to invoke the app to the foreground and then put it back to the background which causes flickers.

John
  • 983
  • 1
  • 13
  • 31
  • 1
    How you receive push messages depends entirely on what you are using for push messaging and that that particular technology supports. Ideally, it delivers the message to you via a `BroadcastReceiver` or `Service`, in which case there is no requirement for you to immediately display a UI. – CommonsWare Jan 31 '17 at 16:02

2 Answers2

-1

You can use Android Services, they can operate in background and have their own lifecycle which can be managed. If you want to process in worker thread, use Intent Service. Developer Docs which I have given link of provide sufficient information about implementation.

Nayan Srivastava
  • 3,655
  • 3
  • 27
  • 49
-1

Is it possible to start an app in the background

Not really, but there is no obligation to show any UI once your app is started so that'd would look like you started in background. In fact it'd be perfectly safe to have all the setup done without any UI. Calling setContentView() in your Activity's onCreate() is not mandatory as is concluding your onCreate() with ordinary finish(). That way you can i.e. start Service w/o showing any UI. There's even theme you can use with activity you do not want to display:

android:theme = "@android:style/Theme.NoDisplay" 

For example, if a push notification is received, then the app is started in the background,

This is different story. Stop using Firebase's "automated" handling and process all pushes yourself. See How to handle notification when app in background in Firebase

Community
  • 1
  • 1
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141