0

i have 2 activities, one is a Database of exercises and the other one is new exercise creator

in this function i create a new class of an exercise, i want to return the new class to the Database activity.

and when creating a new exercise delete this activity and create a new one which will create a new Exercise class.

public void onClickDone(View view)
{
    EditText editText = (EditText) findViewById(R.id.edit_name);
    String name = editText.getText().toString();
    editText = (EditText) findViewById(R.id.edit_description);
    String description = editText.getText().toString();
    editText = (EditText) findViewById(R.id.edit_reptitons);
    EditText editSets = (EditText) findViewById(R.id.edit_sets);
    EditText editTimeBetweenSets = (EditText) findViewById(R.id.edit_time_between_sets_);
    int reptitons = 0 ;
    int sets = 0 ;
    int timeBetweenSets = 0;
    try
    {
        reptitons = Integer.parseInt(editText.getText().toString());
        sets = Integer.parseInt(editSets.getText().toString());
        timeBetweenSets = Integer.parseInt(editTimeBetweenSets.getText().toString());
    }
    catch(NumberFormatException ex)
    {
        AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this);

        dlgAlert.setMessage("please check you input");
        dlgAlert.setTitle("Wrong Input");
        dlgAlert.setPositiveButton("OK", null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }
    _excercise = new Exercise(name, description, reptitons, sets, timeBetweenSets);
}

what is a the best practice for 2 activities to create a class, save it to a list and create a new one when pressing the "create new exercise button" again?

or maybe i should create the instance of the class inside the add exercise activity?

Gilad
  • 6,437
  • 14
  • 61
  • 119
  • Why do you need an *activity* for DB of exercises? Can't you just use a class for accessing your DB? – Mahm00d Jun 07 '14 at 09:39
  • I want to have a main database which is editable by the user. And from that database you are able to create different lists of exercises – Gilad Jun 07 '14 at 11:34
  • I may have understood it incorrectly, but if you're using something like SQLite, IMHO, it's better to separate the class that works with the DB (which actually does operations on DB) and the activity that the user uses to input and edit data. – Mahm00d Jun 07 '14 at 12:54
  • No it's a local class not a real sql db. This class os a list which will contain all the pther classes which are user input. From the db class you u are able to select which classes you want tp you in a certain temp list – Gilad Jun 07 '14 at 15:23

1 Answers1

1

First of all, you're creating objects, not classes.

You can stop Activities using finish(); which should return you to your previous activity.

If you want your second Activity to send Data to the first activity maybe check out startActivityForResult. Check out this topic.

Community
  • 1
  • 1
Torhan Bartel
  • 550
  • 6
  • 33