小编cso*_*orn的帖子

保存片段状态时出现NotSerializableException

我偶尔会看到我不太了解的例外情况.这是我的工作:我有一个界面

public interface IResultProcessor<T> extends Serializable {

    void processResult(T result);

}
Run Code Online (Sandbox Code Playgroud)

,我在这个课程中使用的实例:

public class ConfirmationDialogFragment extends DialogFragment {

    public static void executeAfterConfirmation(FragmentActivity activity, IResultProcessor<Void> runnable,
        String title, String message, int icon, String positiveButtonText, String negativeButtonText) {

        ConfirmationDialogFragment fragment = new ConfirmationDialogFragment();
        Bundle args = new Bundle();
        args.putSerializable(ARG_RUNNABLE, runnable);
        fragment.setArguments(args);
        fragment.show(activity.getSupportFragmentManager(), "dialog");
    }

}
Run Code Online (Sandbox Code Playgroud)

在该onCreateDialog()方法中,我接收IProcessResult实例并在用户确认后执行它.

然后我在一个活动中使用所有这些,如下所示:

@SuppressWarnings("serial") 
IResultProcessor<Void> processor = new IResultProcessor<Void>() {

    @Override
    public void processResult(Void result) {
        new AsyncTask<Void, Void, String>() {

            @Override
            protected String …
Run Code Online (Sandbox Code Playgroud)

android android-fragments

5
推荐指数
1
解决办法
4476
查看次数

标签 统计

android ×1

android-fragments ×1