Reputation: 784
I create a fresh project in Android studio using the wizard that creates a blank activity with a fragment. I then create a second basic activity with a fragment. In the first fragment I add a button, which has an OnClickListener, and inside of onClick() it does the following:
Intent intent = new Intent(getActivity(), SecondActivity.class);
getActivity().startService(intent);
When I click the button, despite the code being run, the activity is never launched. There are no errors in logcat. Because I did it with the wizard, the activity is automatically added to the manifest.
Upvotes: 0
Views: 210
Reputation: 10224
Use startActivity()
insteed of startService()
Intent intent = new Intent(getActivity(), SecondActivity.class);
getActivity().startActivity(intent);
Upvotes: 0
Reputation: 75619
Your code calls startService()
but it should startActivity()
:
Intent intent = new Intent(getActivity(), SecondActivity.class);
getActivity().startActivity(intent);
Upvotes: 3