Issue
I have a very heavy Main Acitivty class which the first time you install the app , freezes until all the data is loaded , I want to show my Splash Screen activity while all the data is loading in the Main Activity and show my activity ONLY when the Main Activity has loaded everything :
Here is my current splash screen activity , currently it only does this:
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
How can I achieve this?
Solution
Regarding the comments on your question, it seems you're trying to update the UI of your MainActivity with the data you're loading. You can query/load your data on the splash activity, pass it on to the intent so you can gather it in onCreate of your MainActivity, or save all your data to SharedPreferences and access it from the MainActivity.
In SplashActivity:
Intent intent = new Intent(this, MainActivity.class);
// inside data loading completion callback or after synchronous data gathering methods
intent.putExtra("key","value");
startActivity(intent);
In MainActivity onCreate method
Bundle extras = intent.getExtras();
String value = extras.getString("key");
You can pass models as json formatted strings if you need.
Answered By - S. Kaan Özkaya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.