Merge pull request #412 from schrockblock/feature/eschrock/on-stop-crash

Crash on recreate MainActivity, and blank tabs
This commit is contained in:
Phillip Thelen 2016-02-09 13:30:10 +01:00
commit 231629ce6d
2 changed files with 21 additions and 0 deletions

View file

@ -182,6 +182,15 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
this.mAPIHelper.retrieveUser(new HabitRPGUserCallback(this));
}
}
//after the activity has been stopped and is thereafter resumed,
//a state can arise in which the active fragment no longer has a
//reference to the tabLayout (and all its adapters are null).
//Recreate the fragment as a result.
if (activeFragment != null && activeFragment.tabLayout == null){
activeFragment = null;
drawer.setSelectionAtPosition(1);
}
}
private void setupCheckout() {

View file

@ -4,6 +4,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -26,6 +27,7 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
public RecyclerView mRecyclerView;
public RecyclerView.Adapter mAdapter;
private String classType;
private static final String CLASS_TYPE_KEY = "CLASS_TYPE_KEY";
// TODO needs a bit of cleanup
public void SetInnerAdapter(HabitItemRecyclerViewAdapter adapter, String classType) {
@ -41,6 +43,10 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
view = inflater.inflate(R.layout.fragment_recyclerview, container, false);
}
if (savedInstanceState != null){
this.classType = savedInstanceState.getString(CLASS_TYPE_KEY, "");
}
switch (this.classType) {
case Task.TYPE_HABIT: {
this.tutorialStepIdentifier = "habits";
@ -86,6 +92,12 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
mRecyclerView.setAdapter(mAdapter);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(CLASS_TYPE_KEY, this.classType);
}
public static TaskRecyclerViewFragment newInstance(HabitItemRecyclerViewAdapter adapter, String classType) {
TaskRecyclerViewFragment fragment = new TaskRecyclerViewFragment();
fragment.setRetainInstance(true);