-1

I have an activity with fragment A added to it dynamically. Now, I transact from fragment A to fragment B. And then from fragment B to fragment C. Now I have a button here when clicked will place a call. I'm not able to start the call intent and the error log says illegal state exception - No activity found to handle the intent. Does it mean that there's no activity found for the nested fragment C? How can this happen (fragment creation without activity)? Also all fragments are dynamically created during run time. I tried this using both getfragmentmanager() and getchildfragmentmanager() method. I face this error in both the cases. Any suggestions would be much appreciated.

Here's my code snippet

Attaching Fragment A to activity

FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.container,FragmentA_.builder().build());
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();

Replacing Fragment A with Fragment B

FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.container, FragmentB_.builder().build());
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();

Replacing Fragment B with Fragment C

FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.container, FragmentC_.builder().build());
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();

Call intent

public void call(String contact){
Intent i=new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+contact));
getActivity().startActivity(i);
}

In my manifest.xml I have added all permissions for Call.

Edit - 2 Fragment C code

@EFragment(R.layout.fragment_c)
public class FragmentC extends Fragment
{
@Click(R.id.call_button)
void call(){
call(phone_number);
}
  public void call(String contact){
    Intent i=new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+contact));
    getActivity().startActivity(i);
    }
}
21
  • No , I am pretty sure that I've followed the order of attachment as mentioned in my question. Also I only added fragment A , rest all fragments I've used replace method. Commented Aug 25, 2016 at 7:26
  • 1
    can you post the code where you are initiating the call intent, also I wanna take a look at your permissions. Commented Aug 25, 2016 at 7:27
  • Could you please share some code ? Commented Aug 25, 2016 at 7:46
  • Code added bro .. Thanks in advance. Commented Aug 25, 2016 at 7:47
  • Have you checked to make sure contact is a valid number? Does ACTION_DIAL work? Commented Aug 25, 2016 at 8:03

1 Answer 1

0

Remove getActivity() and Call directly startActivity(i)

Fragments have its own startActivity() method. You don't need to pass activity context or reference in this case. For more information: Click here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the timely response mate ! Really appreciate it !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.