-1
 Intent intent = new Intent(getActivity(), SecondActivity.class);
    getActivity().startActivity(intent);

//using startActivity(intent) is also not working //the application crashes whatever I do

Talha Khan
  • 1
  • 1
  • 2

4 Answers4

1

use this :

public void goToAttract(View v)
{
    Intent intent = new Intent(getActivity(), MainActivityList.class);
    startActivity(intent);
}
Mehdi Karimi
  • 528
  • 4
  • 25
1

From a Fragment:

Intent intent = new Intent(getActivity(), SecondActivity.class);
startActivity(intent);

From an Activity:

Intent intent = new Intent(this, mFragmentFavorite.class);
startActivity(intent);

Jai Khambhayta
  • 4,198
  • 2
  • 22
  • 29
1

Make sure your SecondActivity is registered in the manifest.

mnp343
  • 329
  • 1
  • 6
0

Please make sure you are using a Fragment , not a FragmentActivity.

See this post Fragment To Activity

Community
  • 1
  • 1
Pc hobbit
  • 96
  • 1
  • 11