1

I created an app that connects to facebook and also downloads some pictures from a server and the profile picture from facebook.

Then I created an exit Button in my app that exits from the account that the user has been logged in with. The app then returns to the login page.

However, when I connect to facebook again after having logged out from the previous account, it shows me an OutOfMemory exception.

Then I increased the VM Heap size from 32 MB to 48MB and it still shows me an OutOfMemory exception.

How can I clear all of the downloaded data till now when the user logs into and then exits from his account in order to avoid from the OutOfMemory exception?

This is my ExitActivity:

public class ExitActivity extends Activity{

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.freinds_listview);

        Session session = Session.getActiveSession();
        if (!session.isClosed()) {
            session.closeAndClearTokenInformation();
        }

        Intent i = new Intent(getApplicationContext(), MainActivity.class);

        startActivity(i);
    }
}
Michael Celey
  • 12,645
  • 6
  • 57
  • 62
Adir Rahamim
  • 453
  • 1
  • 12
  • 31

1 Answers1

0

Could you try using this code when the user logged into the app.

File[] files = cacheDir.listFiles();
for (File file : files){
    file.delete();
}
Castiblanco
  • 1,200
  • 4
  • 13
  • 32
  • hi, thanks for answer, what is the cacheDir? how do i know where cache located? and also, i dont know where the images are download.. – Adir Rahamim Apr 02 '13 at 16:24
  • Actually, I'm not totally sure, but try with this: File cacheDir = context.getCacheDir(); If it works please tell me. – Castiblanco Apr 02 '13 at 16:27
  • hi, i will try it and i will post the answer here, i have another question for you: in a real device, it will remove the cache files of all the other programs that stored in the device? i only want to delete the files of this spesific app and not the whole files that stored in the cache.. – Adir Rahamim Apr 02 '13 at 16:32
  • Regarding to the previous answer using getFilesDir() we just have the file of our app. Good luck men! – Castiblanco Apr 02 '13 at 16:36
  • That's really nice!! What did you use? getFilesDir or the other one? – Castiblanco Apr 02 '13 at 16:48
  • 1
    getFilesDir, and also i add a code to check whether the file is direcotory, and if its a directory i deleted the directory's children too, like here: http://stackoverflow.com/questions/6898090/how-to-clear-cache-android – Adir Rahamim Apr 02 '13 at 17:19