In my app, I have a dual tabbed activity, each tab corresponding to a fragment. In one of my tabs, I prompt the user for an option, which upon confirmation, should switch the tab. So my code for creating the dialog, and switching the tab looks like the following:
new AlertDialog.Builder(getActivity())
.setMessage("Login now with email?")
.setTitle("Prompt")
.setPositiveButton("Yes",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
getActivity().getActionBar().setSelectedNagivationItem(0)})
.show();
However, when I run it, I get a
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo com.package.app/com.package.app.activityname}:
java.lang.ClassCastException: com.package.app.activityname cannot be cast to
android.app.Activity
This error only occurs when I call the method from within the dialog, if I run it when the dialog is not on front, it works. I have also attempted to do it in OnResume() after the dialog dismisses, but it gives me the same error.