that's not the point of the fragment... i meant that the fragment should handle both the logic (and data download) and the UI. then you can just plop it in any activity you want and you're set. Regarding the Application onCreate - Yeah, it will be before anything else, but you dont know how long it would take to finish. it's as pointless as doing it in the first activity. (being a UI thread makes no difference, it's the same thread as in the activities... either way you'd have to pass the work to the background).
On Wednesday, April 17, 2013 7:35:45 PM UTC+3, mbaroukh wrote: > > > If using fragment, I suppose I could make only one activity that will > handle logic (and data download) that will do what AndroidApplication > should and many fragment that won't have to manage more than their own > state. But that did not seems clean to me. > > >Doing it in OnCreate of the application wouldn't help much, you'd still > have to program all activities to know the data is still not there.. so > not much gained here. > > I don't understand why : when application stats, onCreate is call before > anything else. > I can then load sme (small) data statically (eventually ...) and I am sure > I can rely on them while the application is not evicted from memory. > On the application resume, if application has benn destroyed, onCreate() > is called again so there seems not to be any problem here. > Except the (bad) fact I'm on UIThread, of course. > > I'm surprised there no library to handle those activity LifeCycle but I > imagine it must be something tricky. > I suppose the best option would be to use the same process as > http://androidannotations.org/ to generate all the boilerplate code at > compile time. > > Anyway, thanks a lot for your answer. > > Mike > > Le mercredi 17 avril 2013 18:12:34 UTC+2, Piren a écrit : >> >> I'll reply here for both messages: >> Yeah it is android design, i dont like it myself but they did supply some >> help - Fragments... they are the middle ground between pure UI and BL... >> You can have a fragment that handles the whole thing and use it in both >> activities (i personally think that the code to handle the fragments would >> be the same as code to handle a progress dialog :-) ) >> >> Doing it in OnCreate of the application wouldn't help much, you'd still >> have to program all activities to know the data is still not there.. so >> not much gained here. >> >> On Wednesday, April 17, 2013 6:57:11 PM UTC+3, mbaroukh wrote: >>> >>> Service or not every activity must implement a logic to wait for the >>> download to complete isn't it ? >>> So it must have a logic for it own process and a logic for the download. >>> That make those activities more complicated than they have to be. >>> >>> Is it and Android design problem that have no solution and which we have >>> to live with or do I missed something ? >>> >>> Mike >>> >>> Le mercredi 17 avril 2013 17:41:45 UTC+2, RichardC a écrit : >>>> >>>> Use a Service to retrieve and manage the data, Bind the service from >>>> Activity A and B. If the data is available use it, if it not download it >>>> (in the service). >>>> >>>> On Wednesday, April 17, 2013 3:57:28 PM UTC+1, 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.

