oncreate

Android SQLite - why is my db re-created each time?

…衆ロ難τιáo~ 提交于 2020-01-23 08:14:26
问题 I'm trying to get a better understanding of the SQLiteOpenHelper class and how and when onCreate and onUpgrade are called. My problem is that each time I quit and start my application (technically it's actually each time I create a new instance of MyDB), onCreate is called, and all of the data from the previous usage is effectively wiped... WTF??? I got around this problem initially by creating a singleton MyDBFactory where I created a single instance of MyDB. This allowed the data to be

Should I restore savedinstancestate in onCreate or in onRestoreInstanceState?

天大地大妈咪最大 提交于 2020-01-23 04:26:28
问题 I have an activity that starts some other activities for results, so when the result comes back, the activity may or may not have been destroyed and recreated. I have overridden onSaveInstanceState so as to add the data that needs to be preserved and restored. When the activity gets destroyed and recreated, onCreate is passed the savedInstanceState bundle; but also onRestoreInstanceState() is called and passed the same bundle. So where should I put the code that extracts the data from the

Android lock screen behaviour

烂漫一生 提交于 2020-01-17 04:40:09
问题 If I press home and come back to my app a little later I will find that the state has been preserved perfectly. For some reason however if I lock the phone and then unlock it, my app has been returned to the original state bar a few things here and there. When I looked into the logs I found that onCreate had been called while the phone was in a locked state. Because locking the phone is quite an off hand thing to do, having your game reset every time you do so is not desirable to the user.

Set text of spinner before item is selected

时间秒杀一切 提交于 2020-01-12 07:24:08
问题 I have a spinner with three items and I use an XML string-array resource to feed it. When you open an activity the spinner normally shows the first item that's in the array list. I'd like to change that and show the text "Select one" in the spinner, before an item is selected. How can I do that? 回答1: You can do that one of two ways. 1) Add "Select One" as the first item in your xml and code your listener to ignore that as a selection. 2) Create a custom adapter to insert it as the first line,

Want to display AlertDialog in onCreate of Activity - android

ぃ、小莉子 提交于 2020-01-11 07:45:09
问题 In my activity, I call a MyDialog (custom dialog) in onCreate() and handle its DismissListener in Activity to find if its cancelled or not. If its cancelled, I finish the activity, else load the activty. During this loading time, I want to show a Alert/Progress dialog to let the user know that its loading, please wait. But am not able to see the dialog. This is how I have coded : public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ld = new AgreeDialog(this);

Where to set all Listeners?

妖精的绣舞 提交于 2020-01-10 03:37:08
问题 Where to set all Listeners for the user interfaces? Is it good practice to set them in onCreate ? This looks so unstructured and strange. Is there a better place to set them? 回答1: From here: http://developer.android.com/reference/android/app/Activity.html onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource defining your UI, and using findViewById(int) to retrieve the widgets in that UI that you need to

Android: Set Random colour background on create

心已入冬 提交于 2020-01-09 19:31:53
问题 What I want is when I load my app up it to randomly have a certain colored background from a predefined list of strings stored in a values xml file called colours. What I currently have is one colour set as the background defined through the string colour code using the gui editor in eclipse. For the life of me can't work out how to get the background to randomly pick one of the 9 strings and display it each time the activity is activated. Guidance on this would be invaluable. 回答1: In colors

Android: Set Random colour background on create

我的梦境 提交于 2020-01-09 19:31:50
问题 What I want is when I load my app up it to randomly have a certain colored background from a predefined list of strings stored in a values xml file called colours. What I currently have is one colour set as the background defined through the string colour code using the gui editor in eclipse. For the life of me can't work out how to get the background to randomly pick one of the 9 strings and display it each time the activity is activated. Guidance on this would be invaluable. 回答1: In colors

SQLiteOpenHelper failing to call onCreate?

懵懂的女人 提交于 2020-01-09 02:08:11
问题 I am trying to create a local database on an android phone using sqlite . I have a helper class, shown below, that is used to create the database and provide the "help". I am wanting to create an object of this class in the main part of my code and it create the database and tables there as well. The problem: Whenever i create an object of the class, it does not seem to be calling the onCreate method in the helper. I thought this is supposed to happen. I thought that onCreate was basically a

SQLiteOpenHelper failing to call onCreate?

对着背影说爱祢 提交于 2020-01-09 02:07:10
问题 I am trying to create a local database on an android phone using sqlite . I have a helper class, shown below, that is used to create the database and provide the "help". I am wanting to create an object of this class in the main part of my code and it create the database and tables there as well. The problem: Whenever i create an object of the class, it does not seem to be calling the onCreate method in the helper. I thought this is supposed to happen. I thought that onCreate was basically a