TabActivity
을 사용하고 있으며 모든 하위 활동에 탭을 표시하려고합니다. 내가 좋아하는 흐름을 한이 MainActivity(TabActivity)
->TabGroupActivity1(TabGroupActivity)
->Activity1
->TabGroupActivity - startChildActivity - 작동하지 않습니다.
지금은 플래그가 true 인 경우에만 activity2에에 리디렉션 할 Activity2
. 그래서 내 코드는 다음과 같습니다.
TabGroupActivity
public class TabGroupActivity extends ActivityGroup {
private ArrayList<String> mIdList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (mIdList == null) mIdList = new ArrayList<String>();
}
/**
* This is called when a child activity of this one calls its finish method.
* This implementation calls {@link LocalActivityManager#destroyActivity} on the child activity
* and starts the previous activity.
* If the last child activity just called finish(),this activity (the parent),
* calls finish to finish the entire group.
*/
@Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
int index = mIdList.size()-1;
if (index < 1) {
finish();
return;
}
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index); index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();
Window newWindow = manager.startActivity(lastId, lastIntent);
setContentView(newWindow.getDecorView());
}
/**
* Starts an Activity as a child Activity to this.
* @param Id Unique identifier of the activity to be started.
* @param intent The Intent describing the activity to be started.
* @throws android.content.ActivityNotFoundException.
*/
public void startChildActivity(String Id, Intent intent) {
Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
mIdList.add(Id);
setContentView(window.getDecorView());
}
}
/**
* The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
* from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* Overrides the default implementation for KeyEvent.KEYCODE_BACK
* so that all systems call onBackPressed().
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
onBackPressed();
return true;
}
return super.onKeyUp(keyCode, event);
}
/**
* If a Child Activity handles KeyEvent.KEYCODE_BACK.
* Simply override and add this method.
*/
@Override
public void onBackPressed () {
int length = mIdList.size();
if (length > 1) {
Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
current.finish();
}
}
}
이제 코드 Activity1
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(flag){
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
Intent previewMessage = new Intent(parentActivity, Activity2.class);
parentActivity.startChildActivity("Activity2", previewMessage);
}else{
setContentView(R.layout.row);
//...
}
}
이 작동하지 않습니다 지금 TabGroupActvity1
public class TabGroupActyvity1 extends TabGroupActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startChildActivity("OptionsActivity", new Intent(this,Activity1.class));
}
}
,
같은 코드 일부 클릭 이벤트에서 울부 짖는 작품의 하나지만 내 경우 엔 작동하지 않아.
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
Intent previewMessage = new Intent(parentActivity, Activity2.class);
parentActivity.startChildActivity("Activity2", previewMessage);
제안 방법을 알려주세요. 문제를 잘 설명해 주어야합니까 ... 자세한 내용을 추가해야합니까?
(플래그) ... 플래그가 무엇을 포함 같은
TabGroupActivity
에서 다시 키를 처리? 어디에서 초기화할까요? – Karthi
예외가 있습니까? – Praveenkumar
플래그는 사용자 로그인 인 경우 Application 클래스를 확장하는 클래스에서 가져오고 디버거도 if 부분에 있지만 Activity2를 표시하지 않습니다. –