gpt4 book ai didi

java - 在 onSaveInstanceState 解决方法后无法执行此操作

转载 作者:行者123 更新时间:2023-11-30 03:22:39 31 4
gpt4 key购买 nike

这是异常(exception)

09-16 11:48:48.214: W/dalvikvm(3644): threadid=1: thread exiting with uncaught exception (group=0x415c3700)
09-16 11:48:48.214: E/AndroidRuntime(3644): FATAL EXCEPTION: main
09-16 11:48:48.214: E/AndroidRuntime(3644): java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1343)
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1354)
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
09-16 11:48:48.214: E/AndroidRuntime(3644): at com.smedilepaolo.newsfeed.SubscriptionsListActivity.apriAllUnreadItems(SubscriptionsListActivity.java:159)
09-16 11:48:48.214: E/AndroidRuntime(3644): at com.smedilepaolo.newsfeed.SubscriptionsListFragment$GetSubscriptionListTask.onPostExecute(SubscriptionsListFragment.java:466)
09-16 11:48:48.214: E/AndroidRuntime(3644): at com.smedilepaolo.newsfeed.SubscriptionsListFragment$GetSubscriptionListTask.onPostExecute(SubscriptionsListFragment.java:1)
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.os.AsyncTask.finish(AsyncTask.java:631)
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.os.AsyncTask.access$600(AsyncTask.java:177)
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.os.Handler.dispatchMessage(Handler.java:99)
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.os.Looper.loop(Looper.java:137)
09-16 11:48:48.214: E/AndroidRuntime(3644): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-16 11:48:48.214: E/AndroidRuntime(3644): at java.lang.reflect.Method.invokeNative(Native Method)
09-16 11:48:48.214: E/AndroidRuntime(3644): at java.lang.reflect.Method.invoke(Method.java:525)
09-16 11:48:48.214: E/AndroidRuntime(3644): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-16 11:48:48.214: E/AndroidRuntime(3644): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-16 11:48:48.214: E/AndroidRuntime(3644): at dalvik.system.NativeStart.main(Native Method)
09-16 11:48:59.315: I/Process(3644): Sending signal. PID: 3644 SIG: 9

这是导致它的代码

public void apriAllUnreadItems(){

Log.d(TAG, "apriAllUnreadItems");

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();

Fragment oldDetail = fm.findFragmentById(R.id.detailFragmentContainer);
Fragment newDetail;

isTablet = getResources().getBoolean(R.bool.isTablet);
if(isTablet) newDetail=(Fragment) NewsListFragment_Tablet.newInstance(0, 0);
else newDetail=(Fragment) NewsListFragment_Phone.newInstance(0, 0);

if (oldDetail != null) {
ft.remove(oldDetail);
}

ft.add(R.id.detailFragmentContainer, newDetail);
ft.commit();
}

* 编辑异步任务

/************************************************
* GetSubscriptionListTask
************************************************/

private class GetSubscriptionListTask extends AsyncTask<Void, Void, Void> {

boolean onlyUnread=true;

public GetSubscriptionListTask(boolean onlyUnread) {
super();
this.onlyUnread=onlyUnread;
}

ProgressDialog progress;

@Override
protected void onPreExecute() {
//Show progress Dialog here
super.onPreExecute();

// create ProgressDialog here ...
progress = new ProgressDialog(getActivity());
progress.setMessage("Downloading Subscriptions");
// set other progressbar attributes

progress.setCancelable (false);
progress.setIndeterminate (true);
progress.show();

}


@Override
protected Void doInBackground(Void... params) {

if(this.isCancelled()==false){
reader.getSubscriptions(this.onlyUnread);
}

return null;

}

@Override
protected void onPostExecute(Void v) {

/************************************************
* Subscriptions Adapter - ListView
************************************************/



// preparing list data
prepareListData();

listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);

// setting list adapter
expListView.setAdapter(listAdapter);

// setting list adapter
expListView.setAdapter(listAdapter);


expListView.expandGroup(0);
expListView.expandGroup(1);
expListView.expandGroup(2);





mCallbacks.apriAllUnreadItems();

//Dismiss Progress Dialog here
progress.dismiss();

// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {

@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {

Toast.makeText(
getActivity(),
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(
listDataHeader.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT)
.show();



final SubscriptionsArray element= listDataChild.
get(listDataHeader.get(groupPosition)).
get(childPosition);



if(setSourceAsReadToggle.isChecked()==true){
//Chiedo all'utente se vuole settare la sorgente che ha selezionato come letta
displayAlertDialog(element);


}
else{
//Carico News elemento selezionato
mCallbacks.onSubscriptionSelected(groupPosition, childPosition);
}



return false;
}
});


}
}

最佳答案

通过使用 commitAllowingStateLoss() 解决;而不是 commit();

谢谢

关于java - 在 onSaveInstanceState 解决方法后无法执行此操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18825138/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com