Deleting Crime in Master-Detail Crashes App


#1

I notice that if I delete a crime on tablet view, the app will just close in the emulator. I believe it goes to background.
I am not sure if this is an emulator issue or app issue?
Thanks,


#2

Hi. The key is that when u delete the crime from phone, u called the getActivity().finish(), which returned u the CrimePagerActivty(getActivity()). But when u delete the crime from tablet, the getActivity() call returns u the CrimeListActivity. If u finish this Activity, surely u will exit the whole app because u set this Activity android.intent.action.MAIN and android.intent.category.LAUNCHER in ur manifests.xml.

Here is my solution:
In CrimeFragment.java, add a onCrimeDeleted() method to CallBacks interface.

public interface CallBacks { void onCrimeUpdated(Crime crime); void onCrimeDeleted(); }

and in CrimeListActivity.java, implement it.

public void onCrimeDeleted() { FragmentManager fm = getSupportFragmentManager(); fm.beginTransaction() .remove(fm.findFragmentById(R.id.detailFragmentContainer)) .commit(); }

also in CrimePagerActivity.java,

public void onCrimeDeleted() { finish(); }

I found this problem, too. And hope this could help u. :smiley: