2012-11-29 67 views
1

嗨,我有兩個活動,第一個活動有三個圖標,一個是隱形的......當我點擊第一個活動時,它使用intent ..第二個活動活動是一個登錄屏幕,當登錄成功時,我應該回到第一個活動並在第一個活動中顯示一個圖標..如何從第二個活動返回到第一個活動並使該圖標在第一個活動中可見..下面是我的登陸界面代碼Android:展示其他活動的活動視圖

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

使用startActivityForResult – njzk2

回答

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