Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to load FileInputStream in a septate class
- EditText eTuser;
- EditText eTpassword;
- CheckBox StaySignedIn;
- Button bSubmit;
- String user;
- String pass;
- FileOutputStream fos;
- FileInputStream fis = null;
- String FILENAME = "userandpass";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.login);
- eTuser = (EditText) findViewById(R.id.eTuser);
- eTpassword = (EditText) findViewById(R.id.eTpassword);
- StaySignedIn = (CheckBox) findViewById(R.id.Cbstay);
- bSubmit = (Button) findViewById(R.id.bLogIn);
- bSubmit.setOnClickListener(this);
- File file = getBaseContext().getFileStreamPath(FILENAME);
- if (file.exists()) {
- Intent i = new Intent(LogIn.this, ChatService.class);
- startActivity(i);
- }
- //if if file exist close bracket
- try {
- fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
- fos.close();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } // end of catch bracket
- catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } // end of catch
- } // create ends here
- public void onClick(View v) {
- // TODO Auto-generated method stub
- switch (v.getId()) {
- case R.id.bLogIn:
- String user = eTuser.getText().toString();
- String pass = eTpassword.getText().toString();
- Bundle userandpass = new Bundle();
- userandpass.putString("user", user);
- userandpass.putString("pass", pass);
- Intent login = new Intent(LogIn.this, logincheck.class);
- login.putExtra("pass", user);
- login.putExtra("user", pass);
- startActivity(login);
- if(StaySignedIn.isChecked());
- String userstaysignedin = eTuser.getText().toString();
- String passstaysignedin = eTpassword.getText().toString();
- try {
- fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
- fos.write(userstaysignedin.getBytes());
- fos.write(passstaysignedin.getBytes());
- fos.close();
- } catch(IOException e) {
- // end of try bracket, before the Catch IOExceptions e.
- e.printStackTrace();
- } // end of catch bracket
- } // switch and case ends here
- }// Click ends here
- }// main class ends here
- fis = openFileInput(FILENAME);
- byte[] dataArray = new byte[fis.available()];
- while (fis.read(dataArray) != -1); {
- //while statement }
Add Comment
Please, Sign In to add comment