How do I start an activity from within a Fragment?

android, android-activity, fragment

Solution

You should do it with `getActivity().startActivity(myIntent)`

Problem

I have a set of tabs inside of a `FragmentActivity` that each hold their own fragment. When I tried to start a new activity from within that fragment via an `onClickListener`, and using the `startActivity(myIntent)` method, my application force closes. After looking around for a while, I found a reference or two to a method called `startActivityFromFragment`, but after searching around for an hour or so I can't find any explanations or examples of how to use it or whether this is what I should be using. I guess what I'm asking is whether there is any difference between launching a new activity from an activity, and launching a new activity from a fragment, and if so, what do I need to implement?

Original source

Related problems