1

Consider for example, I started a background process in one activity (let's say process to get user's location). Now, before waiting for it's response, I redirected user to another activity. So, I want to know that what will happen to that background process? Will it continue working even after redirection or it will be paused?

Tabish Hussain
  • 852
  • 5
  • 13
Harshil
  • 914
  • 1
  • 12
  • 26
  • What do you mean by "background process"? – David Wasser Dec 06 '16 at 19:55
  • @DavidWasser I mean executing **doInBackground(Params... params)** of **AsyncTask**. – Harshil Dec 06 '16 at 19:58
  • 1
    Please read the linked duplicate question and the very detailed answers. This should explain everything you need to know and more about the relationship between `Activity` and `AsyncTask`. The answers you've gotten are all wrong for `AsyncTask` and since you didn't indicate that you are using `AsyncTask` in your question, the people answering went down the wrong path to help you. Next time please be more specific about what you are using. – David Wasser Dec 07 '16 at 22:12

3 Answers3

3

Short answer: No. It will be paused once you start a new Activity. To achieve such a thing you should look into services

You can find all you need to know here:

Activities

https://developer.android.com/training/basics/activity-lifecycle/index.html

Services

https://developer.android.com/guide/components/services.html

Raymond
  • 2,276
  • 2
  • 20
  • 34
1

if service is unbound service then Service is run continuously

A service is started when an application component, such as an activity, starts it by callingely, even if the component that started it is destroyed. startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed.

Bound

A service is bound when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC).

Surya Prakash Kushawah
  • 3,185
  • 1
  • 22
  • 42
1

If you process isn't in a service or an Intent Service then there is no guarantee that your process will complete. The process should be paused. The proper way to handle this would be to use an Intent Service. Setup an event bus to handle the response. I suggest using Otto as the event bus. Also here's an Intent Service Tutorial.

VirtualProdigy
  • 1,637
  • 1
  • 20
  • 40