Android: Pass information from one activity to another

Viewed 114

I am trying to pass information (more specifically a class with information) from one activity to another. In my application I have a splash screen that is responsible for loading and initializing variables. The goal is to get this information to the actual game itself so it may be used but I don't know how to do so. In my splash screen class I have this method that is responsible for moving from the splash screen to the game once everything is loaded:

private void moveToGame() {
    loop.setRunning(false);
    act.startActivity(new Intent(splash, MainActivity.class));
    act.finish();
    return;
}

The main activity class then has this line of code to get to the actual game:

setContentView(new Environment(this, this));

The constructor for the Environment class is Environment(Context context, Activity act)

The goal is to change the constuctor to Environment(Context context, ActivityAct, LoadInfo li) but how do I pass the information all the way to the Environment constructor?

EDIT 1 - LoadInfo Class

public class LoadInfo {
    private HashMap<String, Typeface> fonts;
    private HashMap<String, Image> images;
    private File logFile;
    private File settingsFile;
    private File gameDir;

    public LoadInfo() {}

    public LoadInfo(HashMap<String, Typeface> fonts, HashMap<String, Image> images, File logFile, File settingsFile, File gameDir) {
        this.fonts = fonts;
        this.images = images;
        this.logFile = logFile;
        this.settingsFile = settingsFile;
        this.gameDir = gameDir;
    }

    public HashMap<String, Typeface> getFonts() {
        return fonts;
    }

    public HashMap<String, Image> getImages() {
        return images;
    }

    public File getLogFile() {
        return logFile;
    }

    public File getSettingsFile() {
        return settingsFile;
    }

    public File getGameDir() {
        return gameDir;
    }

    public void setFonts(HashMap<String, Typeface> fonts) {
        this.fonts = fonts;
    }

    public void setImages(HashMap<String, Image> images) {
        this.images = images;
    }

    public void setLogFile(File logFile) {
        this.logFile = logFile;
    }

    public void setGameDir(File gameDir) {
        this.gameDir = gameDir;
    }

    public void setSettingsFile(File settingsFile) {
        this.settingsFile = settingsFile;
    }

    public boolean fullyLoaded() {
        return fonts != null && images != null && logFile != null && gameDir != null && settingsFile != null;
    }

    public String toString() {
        if(logFile == null)
            return "well no file to load";
        return logFile.toString();
    }
}
2 Answers
Related