I have read this answer here and also this here and I'm trying to figure out what fits best for my case.
I start a Service inside onCreate()
where I make an HTTP requests and I get an id
as a response. I then broadcast this id
and receive it in my activity.
The problem is that the user can obviously navigate to another activity just by opening the drawer and selecting an option and I can miss the broadcast.
I can obviously have all my Activities extend an abstract class which extends Activity
like is mentioned here but I'm not 100% sure its the best solution. What if user decides to quit the app before I receive the id ?
Edit : app architecture
- User captures an image using an Intent to open camera app and get the path of the image file.
FormActivity
starts where user can add some details about the image.- User clicks upload and I pass the data user has just entered to
QuizActivity
. - In
onCreate()
ofQuizActivity
I start anService
where I :- create an empty entry to server and I get an
id
as a response and - upload image to server
- create an empty entry to server and I get an
- That
id
I get as a response from server I then broadcast it. QuizActivity
has anentryIdReceiver
registered where receives theid
and stores it in a private field until user decides to either leave the activity or click to upload the quiz ( if he entered data for the quiz of course )- If user clicks upload I start an
IntentService
with theid
and the quiz data. - If User opens drawer and select another
Activity
or clicks cancel to create a quiz I start anIntentService
to upload theid
with the "empty quiz data" and move user toMainActivity
.
The problem is : what if uer closes app while on QuizActivity
and I haven't yet receive the id
, or user decides to got to another Activity
using the drawer without adding a quiz. I still have to start a service and upload the id
with "empty quiz data".