从片段中阻止运行活动

时间:2017-02-21 18:19:00

标签: android-fragments android-activity

我在android studio中有一些代码。我想要调用此活动:

public void addConversationFragmentStartCall(ArrayList<Integer> opponents,
                                             QBRTCTypes.QBConferenceType qbConferenceType, Map<String, String> userInfo) {
    QBRTCSession newSessionWithOpponents = rtcClient.createNewSessionWithOpponents(opponents, qbConferenceType);
    SettingsUtil.setSettingsStrategy(opponents, getDefaultSharedPrefs(), this);

    Log.d("Crash", "addConversationFragmentStartCall. Set session " + newSessionWithOpponents);
    initCurrentSession(newSessionWithOpponents);
    ConversationFragment fragment = ConversationFragment.newInstance(opponents, "jinkal", qbConferenceType,
            userInfo, StartConversetionReason.OUTCOME_CALL_MADE, getCurrentSession().getSessionID());
    FragmentExecuotr.addFragment(getFragmentManager(), R.id.fragment_container, fragment,
            CONVERSATION_CALL_FRAGMENT);

    if (ringtonePlayer != null) {
        ringtonePlayer = new RingtonePlayer(this, R.raw.beep);
    }
    ringtonePlayer.play(true);
}

我使用此代码点击按钮调用片段:

if (getActivity() != null) {
            ((VideoCallActivity) getActivity()).addConversationFragmentStartCall(
                    oponent, qbConferenceType, userInfo);
                callStatus = 1;
            }

但卡住并得到错误

  

java.lang.ClassCastException:com.going.pass.MainDrawerActivity无法强制转换为com.going.pass.activity.VideoCallActivity

片段中的代码使用此

  

类UberTripFragment扩展了UberBaseFragment

UberBaseFragment中包含以下内容:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = (MainDrawerActivity) getActivity();
    requestQueue = Volley.newRequestQueue(activity);

}

请帮忙解决这个问题..

1 个答案:

答案 0 :(得分:0)

调用它的片段:

if (getActivity() != null) 
{
        ((VideoCallActivity) getActivity()).addConversationFragmentStartCall(
                oponent, qbConferenceType, userInfo);
            callStatus = 1;
}

附加到您的MainDrawerActivity,它必须附加到您的VideoCallActivity。