0

I am trying to make an app which when first loads download all the data onto the application which includes XML of id,name,etc , profile infos, profile image etc. These things I load using a AysnTask which calls my XMLParser which makes the data structure and then on return to doinBackground(), it inserts onto the database with imagelink(profile image). Then onPostExecute(), it starts the gridview which has Imageview as the child, which takes the profile image to load using a ImageLoader example in this tutorial.

Image gets loaded in a class which implements Runnable in run() method, I displayed the image and save that to Sqlite using BLOB. I set a logic in the Runnable class that when last profile image is loaded, it inserts a flag in one of my table, which ensures that next time apps is opened it will get the values from the DB not from the Server.

The issue comes when user close the application some time after opening it however as I have been loading the images in a Runnable so they get broken.... the logic to set the flag does not finished.

How can I make this work?

halfer
  • 19,824
  • 17
  • 99
  • 186
Saty
  • 2,563
  • 3
  • 37
  • 88
  • use singleton class for this i.e ur data will be or flag will be remain untill or unless ur app in stack if u want to store more then use shareprefrence – Bhanu Sharma Mar 21 '14 at 11:29
  • shareprefrence is just same as nsuserdefault in iphone i think u better know about this – Bhanu Sharma Mar 21 '14 at 11:30
  • this is my link for understanding SharedPreferences http://stackoverflow.com/questions/20678669/how-to-maintain-session-in-android/20678802#20678802 – Bhanu Sharma Mar 21 '14 at 11:33
  • okay however how will it help me in this context? I want some thing which will restrict the user to close the app if one Runnable instance is working in background, as my images are getting downloaded through a Runnable class. – Saty Mar 21 '14 at 11:45
  • okay so u mean to say when your async task has been proceed then if user close the app then u want to restrict user to dont do this close is it ur mean – Bhanu Sharma Mar 21 '14 at 11:49
  • Nope !! in AsyncTask my data values get inserted and when it finishes, the gridview starts to load, gridview initlize the download,display image thread which works for all image in gridview I want some thing to happen to prevent userinteraction untill all images are loaded and displayed. – Saty Mar 21 '14 at 11:57

1 Answers1

0

It can be done by sharedpreferences and if you want to do from database then take one Boolean and save image info then when you first time load then make it true and after that any time just fetch that Boolean and if true then {not load again} otherwise {load again}.

Like this for using sharedpreferences when first time load then

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putBoolean("Isload", Isload).commit();//Isloadis a boolean value of your load status
prefsCommit();

and anytime when you want to get status then

     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean Isload= prefs.getBoolean("Isload", false);//get value of last load status

Now check

if(Isload)
        {   //condition true means user is already loaded

    }

else
{
    // condition false take it user on login form 
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49
  • (Meta advice: you have 103 posts containing the letter "u" used as an informal abbreviation for the word "you". This is a lot of material for volunteer editors to repair - please try to stick to technical writing here, to make posts as readable as possible). – halfer Jun 03 '18 at 17:31