Reputation: 995
i am trying to open a SherlockFragment activity from non activity class using this from an normal activity
Android.app.Activity >> NonActivityClass >> SherlockFragmentActivity
Passing this from Activity class to NonActivityClass and trying to start the SherlockFragmentActivity
Code -
private void changeFragment(Activity act) {
Fragment profileFrag = new New_ProfileFragment();
FragmentTransaction transaction = ((SherlockFragmentActivity) act)
.getSupportFragmentManager().beginTransaction();
try {
((SherlockFragmentActivity) act).getSupportFragmentManager()
.popBackStackImmediate(profileFrag.toString(),
FragmentManager.POP_BACK_STACK_INCLUSIVE);
} catch (java.lang.IllegalStateException e) {
}
transaction.addToBackStack(profileFrag.toString());
transaction.replace(R.id.content_frame, profileFrag);
transaction.commitAllowingStateLoss();
((SherlockFragmentActivity) act).getSupportFragmentManager()
.executePendingTransactions();
}
I am getting error in
FragmentTransaction transaction = ((SherlockFragmentActivity) act)
.getSupportFragmentManager().beginTransaction();
Exception - java.lang.ClassCastException: activity cannot be cast to com.actionbarsherlock.app.SherlockFragmentActivity
Upvotes: 0
Views: 134
Reputation: 22038
a. You are aware of the fact that ActionBarSherlock has been deprecated for 2 years?
b.
activity cannot be cast to com.actionbarsherlock.app.SherlockFragmentActivity
pretty much says it all. You can't cast an android.app.Activity
to a SherlockFragmentActivity
because from what I can see SherlockFragmentActivity
doesn't extend android.app.Activity
.
c. You either have to do
activity.getFragmentManager()
or, if you must use SupportFragmentManager
, you first activity has to be a android.support.v4.app.FragmentActivity
so you can do
activity.getSupportFragmentManager()
Either way, get rid of ActionBarSherlock
.
Upvotes: 1