Tejas
Tejas

Reputation: 358

which Operation will perform first in onStart or onCreate in Android

I want to perform one data base Operation once. I want to do this when My Activity is Visible. Where shall I puty my LoadDatabase() function

    LoadDatabase(); 

this is my oncreate of activity

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.retrospectscan); 

    }

this is my onStart

@Override 
protected void onStart()
{
    super.onStart();
}

Where Shall I put my LoadDatabase Code ? So that It will operated only if activity is fully Visible.

If Any other Approach is there please help me.

Upvotes: 0

Views: 211

Answers (2)

Bhavesh Jethani
Bhavesh Jethani

Reputation: 3875

user2737044

use Application context and load your database in application context create().

2nd thing is that, In activity onCreate() call first then it will call onstart().

Upvotes: 0

Atish Agrawal
Atish Agrawal

Reputation: 2877

The complete activity lifecycle is here:

enter image description here

Though loading from database may be lengthy task , you can try doing it in AsyncTask or in onStart.

You can also use it on onResume. This depends on your application use.

Upvotes: 1

Related Questions