S
S
shadowspok2012-12-26 01:23:35
Android
shadowspok, 2012-12-26 01:23:35

Android: Passing data from a Service to a rotating Activity?

There is a Service that requests and processes data and passes the result to the Activity.
The standard solution is to send data using Broadcast.
But Activity can be recreated at any time, for example, when turning.
Accordingly, the BroadcastReceiver in the Activity will also be disabled and the data will not be delivered.
Are there any recommendations on how to proceed in this case, except for adding data to the Application and for the Activity in onCreate to pick it up either after re-creation or the arrival of the Broadcast.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
ara89, 2012-12-26
@ara89

Cache data in a database, memory, or a file from a service.

R
recompileme, 2012-12-26
@recompileme

In a similar situation, I prefer not to step into this pile of shit
1 I register the receiver in oncreate
2 I disable recreate when turning
Please note - for 13 sdk (android:targetSdkVersion=13) and higher - added screenSize (android:configChanges="keyboardHidden|orientation|screenSize" )
But in my case, the delay between request and response is usually less than a second and I don’t see user cases in which the app would crash. Perhaps you have a different case and MB is better suited for AIDL instead of Broadcast s

R
recompileme, 2012-12-26
@recompileme

Although, to be honest, I did not understand the problem at all.
Just the whole point of the broadcasts is that the
activity kicked the intentservice - do a
service, the user started to do it , the
user changed his mind, turned off the activity - started playing the game or chatting on the phone - he already doesn’t need the result the
service has finished - he fired the answer
but activate it didn’t get it because it doesn’t exist anymore
because the user doesn’t give a shit about the answer
and it should be so, because that’s exactly what we wanted - so that
if the activity dies, nothing falls with an error.
And now you want to read the answer to the question asked a week ago at the next launch of the activity ??
Sounds like some bullshit. Well, store the answer in a text file then, for example, and read it at startup.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question