I have 2 activity's and want to send an id to the second one.
in second activity i want to read some requirement`s data from db (such as some config data for example).
i want to know what method of my second activity call first and its guaranteed that run?
Asked
Active
Viewed 509 times
0

YFeizi
- 1,498
- 3
- 28
- 50
-
I didnt understand last line of your question. Can plz share some more detail? – kiturk3 Dec 20 '14 at 05:49
-
i want to know in which method of my second activity i must call my r/w data from db function`s ? – YFeizi Dec 20 '14 at 05:56
-
onCreate ? onStart ? onResume ? or anything else ? – YFeizi Dec 20 '14 at 05:57
1 Answers
0
very first method that will be called is onCreate() method.
for getting data from intent:
1) in your 1st activity:
`Intent i = new Intent("your first activity".this , "your 2nd activity class".class);
i.putExtra("id_variable", "id_value");
startactivity(i);`
2) now coming to your 2nd activity...
-get data from 1st activity
-if you are using AsyncTask class you can get data from 1st intent in onPreExecute method (it will run first)
- than in onPostExecute you can have data from db(using api or anything else)
- than simply call that class in you onCreate() method. :)
Hope that Helps.... :)
Edit:
onCreate will be called for sure... onResume will be called when your app turns into background and returns... onPause will be called when your app is in background....
-
-
-
-
how many an activity will be created ? imagine a user call this with a btn and back by press back btn , and call it again ! this activity created again ? – YFeizi Dec 20 '14 at 06:29
-
every time you coming to your 2nd activity... onCreate will be called. – kiturk3 Dec 20 '14 at 06:32
-
-
http://stackoverflow.com/questions/8515936/android-activity-life-cycle-what-are-all-these-methods-for – kiturk3 Dec 20 '14 at 06:40