빠른 질문 : activitygroup이 있습니다. 해당 활동 그룹 내에서 활동이 있습니다. 이 활동 안에있는 동안 뒤로 누르면. 액티비티의 onBackPressed 메서드가 호출됩니다. - OnBackPressed의 액티비티 그룹이 아닙니다. - 왜 그런가요?ActivityGroups에서 onBackPressed() 비헤이비
편집 : 내 대답은 있지만 문제는 남아 있습니다. 다음은 코드 및 내 원래 문제에 대한 설명입니다.
TabHost 내에서 ActivityGroups를 사용하고 있으므로 onBackPressed를 재정의하도록 "강제 적용"되었습니다. 내 전화를 다시 누르고 내 탭 호스트의 탭을 눌러 문제없이 애플리케이션을 탐색 할 수 있습니다. 하지만 Back을 누르면 인터페이스와 상호 작용할 수 없습니다. 탭 호스트의 탭 중 하나를 다시 누르면 일반과 같은 모든 기능을 사용할 수 있습니다. 왜 이런 일이 일어나는 걸까요? onResume을 재정의해야합니까?
관련 코드
SettingsActivityGroup :
public class SettingsActivityGroup extends ActivityGroup
{
// Keep this in a static variable to make it accessible for all the nested activities, lets them manipulate the view
public static SettingsActivityGroup group;
// Need to keep track of the history if you want the back-button to work properly, don't use this if your activities requires a lot of memory.
private ArrayList<View> history;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Allocate history
this.history = new ArrayList<View>();
// Set group
group = this;
// Start root (first) activity
Intent myIntent = new Intent(this, SettingsActivity.class); // Change to the first activity of your ActivityGroup
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
ReplaceView("SettingsActivity", myIntent);
}
/*
* Replace the activity with a new activity and add previous one to history
*/
public void ReplaceView(String pId, Intent pIntent)
{
Window window = getLocalActivityManager().startActivity(pId, pIntent);
View view = (window != null) ? window.getDecorView() : null;
// Add the old activity to the history
history.add(view);
// Set content view to new activity
setContentView(view);
}
/*
* Go back from previous activity or close application if there is no previous activity
*/
public void back()
{
if(history.size() > 1)
{
// Remove previous activity from history
history.remove(history.size()-1);
// Go to activity
View view = history.get(history.size() - 1);
Activity activity = (Activity) view.getContext();
// "Hack" used to determine when going back from a previous activity
// This is not necessary, if you don't need to redraw an activity when going back
activity.onWindowFocusChanged(true);
// Set content view to new activity
setContentView(view);
}
else
{
// Close the application
finish();
}
}
/*
* Overwrite the back button
*/
@Override
public void onBackPressed()
{
// Go one back, if the history is not empty
// If history is empty, close the application
SettingsActivityGroup.group.back();
return;
}
}
임의 아이 SettingsActivityGroup의 (CallForwardActivity)
public class CallForwardActivity extends ListActivity
{
....
@Override
public void onBackPressed()
{
// Go one back, if the history is not empty
// If history is empty, close the application
SettingsActivityGroup.group.back();
return;
}
}
아무 것도 이상하지 않습니다. 이것을 처리하기 위해 관심을 표명했다면 활동은 그것을 처리해야합니다. else 컨트롤은 활동의 부모 인 활동 그룹을 전달할 것입니다. – jeet