ListView with config.properties

1

I have the following question, I'm using a listview with a 300 character of a game, when clicking on a character it inserts some data that is written in config.properties , all the characters have descriptions, vocations among other information many different.

The code is working correctly, but my question is the way I'm doing to insert the data would not leave the code too heavy? Is there any other right way?

Code:

Util.java

    public class Util {
    public static String getProperty(String key, Context context) throws IOException {
        Properties properties = new Properties();;
        AssetManager assetManager = context.getAssets();
        InputStream inputStream = assetManager.open("config.properties");
        properties.load(inputStream);
        return properties.getProperty(key);

    }
}

IvysaurActivity.java

     @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ivysaur);
        //mToolbar = (Toolbar) findViewById(R.id.Toolname);
        mToolbar = (TextView) findViewById(R.id.Toolname);

 Number = (TextView) findViewById(R.id.Number);
        Level = (TextView) findViewById(R.id.Level);
        Valornpc = (TextView) findViewById(R.id.Valornpc);

  Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            mToolbar.setText(bundle.getString("TituloPokemon"));

            if (mToolbar.getText().toString().equalsIgnoreCase("Bulbasaur")) {

                try {
                    Number.setText(Util.getProperty("Number",getApplicationContext()));
                    Level.setText(Util.getProperty("Level",getApplicationContext()));
                    Valornpc.setText(Util.getProperty("Valornpc",getApplicationContext()));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            else
            if (mToolbar.getText().toString().equalsIgnoreCase("Venusaur")) {

                try {
                    Number.setText(Util.getProperty("Number2",getApplicationContext()));
                    Level.setText(Util.getProperty("Level2",getApplicationContext()));
                    Valornpc.setText(Util.getProperty("Valornpc2",getApplicationContext()));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }


        }
    }
}

config.properties

Number=Teste1
Level=240
Valornpc=28.000;


Number2=Teste2
Level2=540
Valornpc2=58.000;

Thank you in advance

    
asked by anonymous 14.09.2017 / 15:47

1 answer

2

I believe this does not have a "correct" answer, a lot of testing and how you want to create your database and the purpose of your application. For example:

  • If it is only to show data and statistics of pokémons. You can use a less complex approach. Maybe even as you are doing.
  • An offline game. You need to ensure that you can make changes to the properties of each character by malicious users.
  • A multiplayer online game. A much more complex, secure and external approach is needed. Servers, web services, authentications, etc.

Consider that these are just examples and that there are several factors involved. But here are some tips.

If you have a .properties file for each pokemon and its evolutions, then I assure you that it would not be the best option because you would have an exorbitant amount of files. In that case, it would be best to leave all your pokémons in only one .properties ;

You should take into account that this file can be changed by anyone if it is saved locally (which may influence your application depending on the purpose).

A somewhat more secure alternative would be to create a local SQLite bank. It is the most "standard" android form for applications that need to save data locally, but one should take into account the size of the database, not to take up too much space on the user's device.

A sample tutorial .

Another alternative, perhaps the safest but most complex one, is to create a database on a server that communicates through a web-service, where it communicates with your application. This leaves the application completely free to worry about storage, it only performs requests to the web service which in turn returns the data. It's much safer too.

Example android communication with server php and bank MySQL :

    
14.09.2017 / 16:52