Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onClick(View v) {
- if (v.getId()==R.id.saveId){
- String userName = nameEditText.getText().toString();
- String userPass = passEditText.getText().toString();
- userName = userName+" ";
- File file = null;
- FileOutputStream fileOutputStream = null;
- try {
- file = getFilesDir(); //for get file directory
- fileOutputStream = openFileOutput("Mydata.txt", Context.MODE_PRIVATE);
- fileOutputStream.write(userName.getBytes());
- fileOutputStream.write(userPass.getBytes());
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }finally {
- try {
- fileOutputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- Toast.makeText(this, "Data Save Successfully"+file+" /Mydata.txt", Toast.LENGTH_SHORT).show();
- }else if (v.getId()==R.id.secondId){
- Intent intent = new Intent(MainActivity.this,SecondActivity.class);
- startActivity(intent);
- Toast.makeText(this, "Next Activity", Toast.LENGTH_SHORT).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement