0

I need to retrieve from a file one arrayList of Items, but i dont know where i need to put this retrieving code:

List<ItemCultural> cachedEntries = (List<ItemCultural>) InternalStorage.readObject(this, "arquivo.txt");
        regraDeNegocioSingleton.getListaDeItensSingleton().setListaDeItensCulturais(cachedEntries);

And I need to write this object when app closes by this command:

        InternalStorage.writeObject(this, "arquivo.txt", regraDeNegocioSingleton.getListaDeItensSingleton().getListaDeItensCulturais());

My InternalStorage Class:

I tried to Override onDestroy in my MainActivity but dont worked, and i put the retrieving code in my onCreate, but this method always called, not only time. Thanks!

Breno Henrique
  • 81
  • 1
  • 10
  • This can help for the latter part of your question: https://stackoverflow.com/questions/24759941/what-method-is-being-called-when-i-close-an-app – Matt C Mar 04 '16 at 02:18

1 Answers1

0

you're referring about onCreate and onDestroy in an activity right, when the activity starts call onCreate method and when the app closes can call onDestroy method. So, if you want a class call when the Application starts you're talking about this (example):

public class RemindMe extends Application {

@Override
public void onCreate() {
    super.onCreate();

     //add whatever you want

      }
 }

and add this class to your manifest like this:

   <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:name=".Model.RemindMe"/>

and in your MainActivity add this lines:

     remindMe = (RemindMe)getApplication();
     remindMe.onCreate();

hope you can solve your issue :)

  • but onCreate is called so many times right? I need to retrieve informations of my text just one time. Thanks a lot! – Breno Henrique Mar 04 '16 at 01:27
  • nope this class is called only one time while the app starts,before the app run the other clases depending of your logic :), but if you want retrieve info of one textview you need retrieve a view – Julio Cuellar Mar 04 '16 at 16:31