0

I have two activity names (ActivityMain and splash_screen). My problem is the ActivityMain Content, which causes it to be loaded too late.

I want to have a splash_screen page like mobile games and load ActivityMain in the splash_screen background. And when the ActivityMain is fully loaded, splash_screen will be closed.

I want to display a splash screen until ActivityMain is fully loaded.

1 Answers1

0

From my understanding of your question, you can load all the data that the second activity requires to display, in the first activity (Splash Activity) and then pass the data or the list of data that first activity has created through POJO classes that implement Serializable or list of data through Parcellable. You would not need AsyncTask in the first activity, since you want the app to remain in that screen as long as it takes to load the data. You can pass POJO class object from first activity to second activity using Intent.

  1. Construct POJO objects using data queried from database.
  2. Pass data from first activity to second using code:

    //To pass:
    intent.putExtra("MyClass", obj);
    
    // To retrieve object in second Activity
    getIntent().getSerializableExtra("MyClass");
    

Also make sure, each nested class of your main custom class has implemented Serializable interface to avoid any serialization exceptions. For example:

class MainClass implements Serializable {

public MainClass() {}

public static class ChildClass implements Serializable {

    public ChildClass() {}
    }
}

Reference

ravi
  • 899
  • 8
  • 31
  • I have two activity names (ActivityMain and splash_screen). My problem with ActivityMain is because there is a lot of hubs in it. I want to have a splash_screen page like mobile games and load ActivityMain in the splash_screen background. And when the ActivityMain is fully loaded, splash_screen will be closed. I want to display a splash screen until ActivityMain is fully loaded. – amirali saemi Jul 16 '18 at 11:25
  • @amiralisaemi ActivityMain is fully loaded? How can one know if the other activity is fully loaded before even the activity is created?. Splash screen can load all the data for the MainActvity and then when the SplashActivity has all the data necessary to draw onto the MainActivity screen, you can put the data onto the intent and then `startActivity()` using that intent so that MainActivity wont have to worry about loading data, it just has all the data. – ravi Jul 16 '18 at 12:16
  • Does all mobile games do this? Is this standard work? – amirali saemi Jul 16 '18 at 12:25
  • @amiralisaemi I would not know what games would do, but apps would certainly do something similar to this. – ravi Jul 16 '18 at 12:55