C
C
CeBePHblY2016-04-22 15:44:28
Android
CeBePHblY, 2016-04-22 15:44:28

How to make one AsyncTask for multiple Activities?

Is there a way to make one asynctask so that two or more activities can access it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dostelon, 2016-04-23
@dostelon

Service

D
Denis Zagaevsky, 2016-04-23
@zagayevskiy

You were correctly told that asynctask is not an option. The correct solution in such a situation is Service . At the very beginning, you can create a service using startService, then from each activity you can bind to it using bindService. The service runs in the MainThread, so the tasks must be moved to a separate thread (but God forbid you use asynctask before doing this). Look at the implementation of IntentService, it's not quite what you need, but it's easy to complete it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question