How to prevent an Activity from being created again? Is calling it once?

Asked

Viewed 107 times

1

I am making a form and when I finish filling the form I need to change the color of the item of a Listview with the name of the form I just filled and leave the color there independently if I am browsing the application and going through Activity several times, Does anyone know how to do that? let onCreate be called only once.

  • 2

    Put your code in the question so we can better understand the problem.

  • I do not think there is much way to achieve this... The ideal would be to persist this color as a value in SharedPreferences and fetch whenever you need.

2 answers

1

I believe you try to alter the life cycle of Activity will not be very successful.

What you can do is save your information in a static variable, so independent of the Activity be created or not the value will always be the same. Example:

public static ArrayAdapter meu_adapter;

So yours Adapter shall maintain the information at all times, independently of Activity is destroyed and created.

If there is a need to keep the colors after closing the App recommend saving in a database SQLite the records.

0

You can do the following, whenever you finish filling the form you change your listview Adapter and call the method meu_adapter.notifyDataSetChanged().

I answered something similar here /a/81604/16057

Browser other questions tagged

You are not signed in. Login or sign up in order to post.