"Don't let the "UI" handle the data (activity), add a Business Logic layer 
to do that."

I totally agree with that and data is loaded from a separate layer actually 
called by activity A.
But I was looking how to avoid to have each activities call the 
initialisation of this layer.

It seems obvious that the initialisation should be done in onCreate of 
AndroidApplication.
In case of resume, onCreate() is called.
But then, the screen is black and we have no way (as I know) to provide a 
layout on screen that, anyway would have not been displayed because we are 
on the UIThread.

I hate to have to tell every activity that starts to
- check if data is available
- not available then use asynctask to display dialog and download.
- and don't forget to do nothing in onResume() in this case and wait for 
the download to finish before calling what have to be done onResume()
- .. and lot of other case to handle.

That's a lot of boilerplate code to do this.
I was hoping there was something I was missing.
It would be so simple if we could handle ActivtyLifecycle somewhere.

Do I have to resign to see lot of code that will be copy/pasted and will 
introduce errors ?

Mike

Le mercredi 17 avril 2013 17:28:40 UTC+2, Piren a écrit :
>
> Don't let the "UI" handle the data (activity), add a Business Logic layer 
> to do that.
>
> I.E - create a class that is responsible for managing this data. if data 
> is present, load from DB, if not, download for the net. Then let whichever 
> activity that needs the data, interact with that class instead.
>
> BTW, making "order" assumptions for activities on android is a mistake, 
> exactly for the reasons you specified. You should not base your code in a 
> way that assumes something happened earlier in the app. And if you do need 
> to make that assumption, make sure the code works even if the assumption 
> turns to be wrong. In some cases, by forcing the order (dont let activity B 
> launch normally and revert to A).
>
>
> On Wednesday, April 17, 2013 5:57:28 PM UTC+3, mbaroukh wrote:
>>
>> I have a problem that appear on every new developpement.
>> I never found a clean way to handle it so I'm asking for your help.
>>
>> Suppose you have an app that rely on data coming from network.
>> Every activity needs those data.
>>
>> So my approach actually is to handle the download by the first activity 
>> and store it so it will be widely available.
>> No other activity will be launched before data is stored so every 
>> activity will be sure it will be always available.
>>
>> Suppose we have the sequence
>> Activity A (that load data)
>> Then Activity B that use data
>> Then application goes to background
>> is killed by system
>> is wake up on B
>> ==> No problem because data is stored so it will be available and all 
>> will be fine.
>>
>> But, suppose that before to be waked up, data is cleared.
>> The application wake up on activity B with no data available.
>> There will be a NPE.
>>
>> Of course, I can add in the OnCreate() method of application B that, if 
>> data is not available, launch activity A and finish.
>> But I also have to handle it in onResume(), on Pause(), on Create(), 
>> onDestroy().
>> And I have to make it in all my application's activities that use data 
>> which is not really clean.
>>
>> I don't wan't that all my activities inherit from a single one.
>> I don't wan"t to have only one activity with lot of fragments.
>>
>> The best option whould have been that the Android Application object is 
>> able to handle startup and change the first intent in certain conditions.
>> then, if we are going to run B and data is not available, lauch A instead.
>> but sadly, this is not possible.
>>
>> So my question : How do you handle this kind of problem ?
>>
>> Thanks for any advice.
>>
>>
>> Mike
>>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to