【发布时间】:2024-04-27 13:20:01
【问题描述】:
每当我启动我的应用程序时,即使是从创建了现在文件的新模拟器,它仍然会执行一些代码,这表明如果文件已创建执行此意图,我不明白,它不应该,我没办法测试,因为我是iPhone而不是安卓手机,理论上不应该调用代码,只能在第二次加载应用时调用。
谢谢!
代码:
Public class LogIn extends Activity implements OnClickListener {
Button send;
EditText user;
EditText pass;
CheckBox staySignedIn;
FileOutputStream Fos;
String a;
String b;
String string = a;
String string2 = b;
String DANNYISREALLLLYYYGAAYYYYYIMNOTBS;
String FILENAME = "userandpass";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
send = (Button) findViewById(R.id.bLogIn);
user = (EditText) findViewById(R.id.eTuser);
pass = (EditText) findViewById(R.id.eTpassword);
staySignedIn = (CheckBox) findViewById(R.id.Cbstay);
send.setOnClickListener(this);
File file = getBaseContext().getFileStreamPath(FILENAME);
if (file.exists());
Intent i = new Intent(LogIn.this, ChatService.class);
startActivity(i);}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bLogIn:
if (pass.length() == 0)
Toast.makeText(this,
"Try to type in your username and password again!",
Toast.LENGTH_LONG).show();
else if (user.length() == 0)
Toast.makeText(this,
"Try to type in your username and password again!",
Toast.LENGTH_LONG).show();
{
if (staySignedIn.isChecked()) {
String a = user.getText().toString();
String b = pass.getText().toString();
File f = new File(FILENAME);
try {
Fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
if (Fos != null) {
Fos.write(a.getBytes());
Fos.write(b.getBytes());
}
Fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
String u = user.getText().toString();
String p = pass.getText().toString();
Bundle send = new Bundle();
send.putString("key", u);
send.putString("key1", p);
Intent c = new Intent(LogIn.this, logincheck.class);
c.putExtra("key", u);
c.putExtra("key1", p);
startActivity(c);
Toast.makeText(this, "Were signing you in!", Toast.LENGTH_LONG)
.show();
if (!staySignedIn.isChecked()) {
finish();
break;
}
}
}
}
}
}
}
【问题讨论】:
标签: java android file if-statement try-catch