android - Using context in an AsyncTask via a Fragment that has no UI -


i have had app working activities , working on converting fragments in order improve ui.

previously activity started asynctask , passed in used context when methods required (not ui operations, calls shared preferences , content providers). have learnt approach can lead undesirable outcomes if activity destroyed , garbage collected, did compile , run fine.

i began change because wanted make loading screen behave better when app paused , stopped. realised people frown on loading screens in android me required have operation take 20 seconds or , needs completed before app function.

so using this guide, began improving app.

in short guide moves asynctask fragment not have an attached ui, separate fragment displaying loading screen progressbar. means fragment spawns asynctask not have context, meaning cant pass 1 in asynctask.

as said before have operations in asynctask require context object, can from? should pass in data asynctask before start?

as far know, context not static property, need 1 object retrieve it.

thus, can either go "hack-way" in post:

static way 'context' on android?

or can follow android guidelines , use service background loading. remember asynctask utility class designed in background operations later need communicate ui, should use asynctask in correlation ui object. if you, instead use service, got no problem, since service object context need.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -