嗨,我有两个活动,第一个活动有三个图标,一个是看不见的......当我点击第一个活动时,它转到使用intent的第二个活动。我的第二个活动是登录屏幕,当登录成功时我应该回到第一个活动,并在第一个活动中显示一个图标。我可以回到第二个活动的第一个活动,并在第一个活动中显示图标。下面是我的登录屏幕代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fyelogin);
etPassword = (EditText)findViewById(R.id.password);
btnLogin = (Button)findViewById(R.id.login_button);
btnCancel = (Button)findViewById(R.id.cancel_button);
lblResult = (TextView)findViewById(R.id.result);
final ImageView details = (ImageView)findViewById(R.id.red);
btnLogin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String password = etPassword.getText().toString();
if(password.equals("guest")){
lblResult.setText("password successful.");
// details.setVisibility(View.VISIBLE);
} else {
lblResult.setText("password doesn't match.");
}
finish();}});
任何建议/帮助表示赞赏......
答案 0 :(得分:2)
使用startActivityforResult
打开登录活动..然后在第一个活动的onActivityResult(int, int, Intent)
中显示图标..
示例:
public class MyActivity extends Activity {
...
static final int PICK_CONTACT_REQUEST = 0;
protected boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
// When the user center presses, let them pick a contact.
startActivityForResult(
new Intent(Intent.ACTION_PICK,
new Uri("content://contacts")),
PICK_CONTACT_REQUEST);
return true;
}
return false;
}
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == PICK_CONTACT_REQUEST) {
if (resultCode == RESULT_OK) {
// A contact was picked. Here we will just display it
// to the user.
startActivity(new Intent(Intent.ACTION_VIEW, data));
}
}
}
}
检查http://developer.android.com/reference/android/app/Activity.html