问题描述
- FragmentActivity强制转换为Activity
-
public class BaseFragment extends Fragment {protected MainActivity mainActivity; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mainActivity = (MainActivity)getActivity(); } protected void intent2Activity(Class<? extends Activity> artActivity){ Intent intent = new Intent(mainActivity,artActivity); startActivity(intent); }
}
mainActivity = (MainActivity)getActivity();
报错:Cannot cast from FragmentActivity to MainActivity
解决方案
(Activity)xxxxx,这样就可以了
时间: 2025-01-20 16:44:04