Deleting Crime in Master-Detail Crashes App


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?


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, add a onCrimeDeleted() method to CallBacks interface.

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

and in, implement it.

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

also in,

public void onCrimeDeleted() { finish(); }

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