I want to run a function from main activity, but function is another fragment. This is my code
FragmentManager fm = getSupportFragmentManager();
ConversationFragment fragment = (ConversationFragment)fm.findFragmentById(R.id.container);
fragment.addMessageToList("ok");
I placed this code to onCreate
in MainActivity
, and this is the addMessageToList
function in fragment:
public void addMessageToList(String message) {
Log.w("Step 2",message);
}
But my app is crashing. Here logcat:
How can I fix it ?