0

I want to make a voice recognition android app. I want to know how to make database of the app. My app will be using some commands such as accept call for accepting a call, open'UC browser for opening UC browser and some other commands like that. For now i have made six activities in which i have shown what commands should be used for different tasks and each activity is connected with a next button. Now I want that when i click the finish button which is in the sixth activity the app will run in the background and works as it recieves some commands. My app name is JARVIS. I will attach all six activities .

Any help would be deeply appreciated! :)

MainActivity

   public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button Next = (Button) findViewById(R.id.button1);
        Next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), DisplayMessageActivity.class);
                startActivityForResult(myIntent, 0);
            }
        });

    }
}

DisplayMessageActivity

    public class DisplayMessageActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_message);

        Button pre = (Button) findViewById(R.id.button2);
        pre.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
            }
        });
        Button Next = (Button) findViewById(R.id.button3);
        Next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), ThirdActivity.class);
                startActivityForResult(myIntent, 0);
            }
        });
      }
    }

ThirdActivity

        public class ThirdActivity extends AppCompatActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.third_activity);

            Button previous = (Button) findViewById(R.id.button4);
            previous.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }

            });

            Button next = (Button) findViewById(R.id.button5);
            next.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent myIntent = new Intent(view.getContext(), FourthActivity.class);
                    startActivityForResult(myIntent, 0);
                }
            });
        }
        }

FourthActivity

    public class FourthActivity extends AppCompatActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.fourth_activity);

            Button previous = (Button) findViewById(R.id.button6);
            previous.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }

            });

            Button next = (Button) findViewById(R.id.button7);
            next.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent myIntent = new Intent(view.getContext(), FifthActivity.class);
                    startActivityForResult(myIntent, 0);
                }
            });
        }
    }

FifthActivity

    public class FifthActivity extends AppCompatActivity {


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.fifth_activity);

            Button previous = (Button) findViewById(R.id.button8);
            previous.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }

            });


            Button next = (Button) findViewById(R.id.button9);
            next.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent myIntent = new Intent(view.getContext(), SixthActivity.class);
                    startActivityForResult(myIntent, 0);
                }
            });
        }
    }

SixthActivity

    public class SixthActivity extends AppCompatActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.sixth_activity);

            Button previous = (Button) findViewById(R.id.button10);
            previous.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }

            });
        }
    }
hysabone.com
  • 2,959
  • 2
  • 15
  • 26

1 Answers1

0

You can create SQLite databases in Android. In order to create an SQLite Database inside your app, you can use two classes namely SQLiteOpenHelper and SQLiteDatabase (you can use just the latter but the former is so called because it helps you use the latter). Both of these classes are provided in the Android SDK.

    1. SQLiteOpenHelper:
      • This class is used for the creating, upgrading and downgrading (version management) of SQLite databases.
      • There is more information here SQLiteOpenHelper
    1. SQLiteDatabase:
      • This class is used for managing SQLite Databases such as for, creating, dropping and altering the tables in the database, inserting, updating and deleting the data which resides in columns, which are in rows inside a table, which are themselves within the database.
      • It is also used for transactions inside the database.
      • There is more information here SQLiteDatabase

You can inherit the SQLiteOpenHelper class inside your app and get the database from it, or as is often the case, access custom methods within the SQLiteOpenhelper class to manage the database.

For more info on using an SQLite Database, visit the following link:

Saving Data Using SQLite

There is also the Room Persistence Library which is an abstract Layer around SQLite allowing fluent access to SQLite. Saving Data Using the Room Persistence Library

MikeT
  • 51,415
  • 16
  • 49
  • 68
Varun Kumar
  • 1,241
  • 1
  • 9
  • 18