0

나는 내가 ActivityGroup이 그 탭 중 하나에서 TabHost를 포함하는 응용 프로그램을 개발하고있어,이 ActivityGroup에서, 나는 다른 SubActivity (의 난이 Activity을 시작 가정 해 봅시다)를 시작하고, 이 때까지 모든 것이 OK입니다.이동은

문제는 내가 BACK 버튼에서, CurrentActivity (Activity A)가 파괴 눌러하지만 ParentActivity합니다 (ActivityGroup)이 재개되지 않으며, 내 응용 프로그램의 제목 (와 응용 프로그램 쇼 단지 널 창 때입니다 "내 신청서 제목").

View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView(); 
this.setContentView(view); 

그리고 난 내 ActivityGroup이 같은 방법 onKeyDownoverrided 있습니다 :

ActivityGroup에서 Activity을 실행하는 코드 것은

@Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) { 
     Log.i(TAG, "onKeyDown"); 
     if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){ 
      Activity current = getLocalActivityManager().getCurrentActivity(); 
      Log.i(TAG, current.getIntent().getStringExtra("id")); 
      current.finish(); 
      return true; 
     } 
     return super.onKeyDown(keyCode, event); 
    } 

하지만 보인다 방법 onKeyDown ai가 "onKeyDown"로그를 표시하지 않았기 때문에 호출되지 않습니다.

과 로그 캣 디스플레이가 그냥이 :

01-05 11:04:38.012: W/KeyCharacterMap(401): No keyboard for id 0 
01-05 11:04:38.012: W/KeyCharacterMap(401): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 

내가 원하는 것은 표시하는 것입니다 ActivityGroupActivity A를 파괴 할 때.

NB : 내 응용 프로그램 수준은 4 : * 안드로이드 1.6 *, 그래서 내가 할 수없는override방법 onBackPressed()

는 당신의 도움에 대해 감사

----------------------------------- EDIT ------------- ---------------------------

내가 내 Activity (A)에이 같은 내 onKeyDown의 코드를 추가 한 :

@Override 공공 부울 onKeyDown에 (INT 키 코드, KeyEvent를 이벤트) {내 ParentActivity에서

if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){ 
     ParentActivity parentActivity = (ParentActivity) this.getParent(); 
     parentActivity.onKeyDown(keyCode, event); 
     return true; 
    } 
    return super.onKeyDown(keyCode, event); 
} 

그리고, 난이 :

@Override 
    public boolean onKeyDown(int keyCode, KeyEvent event) { 
     if(keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){ 
      Log.i(TAG, "onKeyDown"); 
      int len = idOfSubActivities.size(); 
      String idOfCurrentActivity = idOfSubActivities.get(len-1); 
      Activity currentActivity = getLocalActivityManager().getActivity(idOfCurrentActivity); 
      currentActivity.finish(); 
      idOfSubActivities.remove(len - 1); 
      return true; 
     } 
     return super.onKeyDown(keyCode, event); 
    } 

내가 같은 결과를 얻었다는 Activity A는 정지하지만, 여전히 나에게 일에 널 창을 제공 전자 내 응용 프로그램의 제목, 그리고 내가 먼저 ActivityGroup의 실험을 시작했을 때 나는이 비슷한 문제에 직면 내 ActivityGroup ( ParentActivity)

답변

1

표시되지 않습니다. 문제는 onKeyDown()Activity에 두어야한다는 것입니다. 그러나 ActivityGroup에 대한 참조가 있으려면 Activity이 필요합니다. 그런 다음 뒤로를 누르면 ActivityGroup에 자신의 onBack()으로 전화하십시오.아래에서

내 응용 프로그램에서 탐색 및 역사를 처리하는 벗었 ActivityGroup 코드에 대한

(편집) 다음은 샘플입니다. 그것은 즉석에서 조정되었으므로 오류가있을 수 있습니다. 좀 더 세밀한 점을 주목하십시오.

public boolean onKeyDown(int keyCode, KeyEvent event) 
{//If back was pressed 
    if (keyCode==KeyEvent.KEYCODE_BACK) 
    { MyGroup.getGroup().back(); 
     return true; 
    } 
    return super.onKeyDown(keyCode, event); 
} 

그냥 당신이 아무것도 재미에 KeyDownListener 설정되지 않은 것을 확인하고 잘 작동합니다 :

public class MyGroup extends ActivityGroup 
{ 
/** Static Reference to this Group. */ 
    static MyGroup instance; 
/** Keeps Track of the History as a Stack. */ 
    private ArrayList<View> myActivityHistory; 

    @Override protected void onCreate(final Bundle savedInstanceState) 
    {//Call the Base Implementation 
     super.onCreate(savedInstanceState); 

    // Initialize the Activity History 
     myActivityHistory = new ArrayList<View>(); 

    // Build the Intent 
     Intent _root = null; 
    //Lists the Applications 
     _root = new Intent(this, MyActivity.class); 
    // Send the Index to the Child Activity 
     _root.setAction(Intent.ACTION_VIEW); 
    // Forward the Extras, if they are there 
    // Start the root Activity within the Group and get its View 
     final View _view = getLocalActivityManager().startActivity("App Preferences", _root).getDecorView(); 
    // Start the History 
     addNewLevel(_view); 
    } 

    /** 
    * Gets the instance of the {@link ApplicationGroup} that the child Activity 
    * belongs to. 
    * 
    * @param index 
    * The Group that was passed to the child in the {@link android.content.Intent 
    * Intent} via an Extra (int). 
    * @return 
    * <b>ApplicationGroup -</b> The group that this child was assigned to. 
    */ 
    static public ApplicationGroup getGroup() 
    { if (instance != null) 
      return instance; 
    } 

    /** 
    * Allows the Child to replace the {@link ApplicationGroup}'s current 
    * {@link android.view.View View} with the specified View. This is 
    * intended to be used specifically by the Child. 
    * 
    * @param withView 
    * The View to use for replacement. 
    */ 
    public void addNewLevel(final View withView) 
    {//Adds the old one to history 
     myActivityHistory.add(withView); 
    // Changes this Groups View to the new View. 
     setContentView(withView); 
    } 

    /** 
    * Takes the specified {@link android.app.ActivityGroup ActivityGroup} back 
    * one step in the History to the previous {@link android.view.View View}. 
    */ 
    public void back() 
    { Log.d("Group", "Back overridden"); 
     //If there are more than one screen 
     if (myActivityHistory.size() > 1) 
     { Log.d("Group", "History called"); 
     // Remove the most recent View 
      myActivityHistory.remove(myActivityHistory.size()-1); 
     // Change the View back. 
      setContentView(myActivityHistory.get(myActivityHistory.size()-1)); 
     } 
    // Otherwise Exit 
     else 
     { Log.d("Group", "Program finished"); 
      finish(); 
     } 
    } 

} 

다음 활동을위한 관련 코드입니다. :) 내가 실제로 한 그룹의 배열 (한 번에 3)에 있기 때문에 내가 만든 변경 사항입니다. 기본적으로 Group을 Singleton으로 만들어서 항상 동일한 인스턴스를 가질 수 있으며 History의 뷰를 유지할 수 있습니다. 그런 다음 뒤로를 클릭하거나보기를 추가 할 때 기록을 참조하십시오. 이 도움이

희망, 당신이 나에게 말했다와 내가 같은 결과를 가지고 무엇을

+0

내가 이것을 시도 할 것이다, 내 편집을 참조하십시오 귀하의 회신 : – Houcine

+0

에 대한 감사, 내가했던 FuzzicalLogic, 당신은 몇 가지를 제공하시기 바랍니다 수 있습니다 당신이 말한 코드에 대해 고마워요. – Houcine

+0

예, 잡기 위해 몇 시간을주세요. (나는 일하고있어 내가 집에서 사용하는 응용 프로그램입니다.) ... –

관련 문제