Skip to content Skip to sidebar Skip to footer

Illegalstateexception While Casting Context

I am trying to cast an activity to a FragmentActivty object so I could get FragmentManager object public class Main extends ListActivity { ... public void showTimePickerDialog(V

Solution 1:

I cant use getFragmentManager directly because my activity extends from ListActivity which is very necessary.

It isn't necessary. You can have a ListView in any activity.

Since you're already using fragments, consider using a ListFragment with a FragmentActivity.

Solution 2:

You can't cast Application Context to Activity, you must need Activity Context.

(FragmentActivity) getApplicationContext() // Not Possible

getContext(): Returns the context the view is currently running in. Usually the currently active Activity.

getApplicationContext(): Returns the context for the entire application (the process all the Activities are running inside of). Use this instead of the current Activity context if you need a context tied to the lifecycle of the entire application, not just the current Activity.

Post a Comment for "Illegalstateexception While Casting Context"