プログラミングには新しいので、私は断片でnaviagationドロワを持っています。私のデバイスを回転させると、「アプリを再起動する」か、ホームフラグメントが呼び出されます。私はそれを修復する方法をよく分かりませんが、super.onCreate(savedInstance)に関連していますが、実装する方法は見つかりませんでした。私は運がないマニフェストでonConfigurationChangedメソッドを試しました。私は別のチュートリアルからコードをコピーして、私のアプリが機能するようにしています。もし、コードの投稿が私が投稿すべきものでなければならないかどうかわかりません。ありがとう。オリエンテーションで私のアプリが再開されます
public class MainActivity extends FragmentActivity {
private DrawerLayout mDrawerLayout;
ImageView home;
Fragment fragment = null;
TextView appname;
ExpandableListView expListView;
HashMap<String, List<String>> listDataChild;
ExpandableListAdapter listAdapter;
List<String> listDataHeader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String fontPath = "neue.ttf";
setContentView(R.layout.activity_main);
home = (ImageView)findViewById(R.id.home);
home.setOnClickListener(homeOnclickListener);
appname = (TextView)findViewById(R.id.appname);
Typeface tf = Typeface.createFromAsset(this.getAssets(), fontPath);
appname.setTypeface(tf);
setUpDrawer();
}
private void setUpDrawer() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));
mDrawerLayout.setDrawerListener(mDrawerListener);
expListView = (ExpandableListView) findViewById(R.id.lvExp);
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
expListView.setAdapter(listAdapter);
fragment = new Home();
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerLayout.closeDrawer(expListView);
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
switch (groupPosition) {
case 0:
switch (childPosition) {
case 0:
fragment = new 1();
break;
case 1:
fragment = new 2();
break;
case 2:
fragment = new 3();
break;
...
}
break;
case 1:
switch (childPosition) {
case 0:
fragment = new 4();
break;
...
default:
break;
}
break;
...
}
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerLayout.closeDrawer(expListView);
return false;
}
});
}...
マニフェストファイルでは、'アンドロイドを追加します。これにより、アクティビティがオリエンテーション変更を破棄して再び作成されることを防ぎます。また、アクティビティでサポートライブラリからAppCompatActivityを継承させることもできます。これは後方互換性のためのより良いアプローチであり、configeChangesタグが確実に動作するようにします。 – chRyNaN
ありがとう私はそれを試してもそれは仕事をしなかった –
Shadab Ansariはその答えは私がたくさんの助けをpespondedしかし、私は最後に私のアプリをクラッシュしなかった他の方法で回転問題の解決策を見つけたあなたはそれがここにあるのを見たいと思っているhttp://stackoverflow.com/questions/36900671/app-crashing-after-i-rotate-device-and-click-the-menu/36901929#36901929 –