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.
FormActivitystarts 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()ofQuizActivityI start anServicewhere I :- create an empty entry to server and I get an
idas a response and - upload image to server
- create an empty entry to server and I get an
- That
idI get as a response from server I then broadcast it. QuizActivityhas anentryIdReceiverregistered where receives theidand 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
IntentServicewith theidand the quiz data. - If User opens drawer and select another
Activityor clicks cancel to create a quiz I start anIntentServiceto upload theidwith 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".