1
First of all lose by mistakes (keyboard bugle).
Well I’m trying to call an Activity through the code below, this code is in my Mainactivity.java. I created the Fragments to be called through the Drawer Menu and it works perfectly. My goal is to be able to call an Activity directly from this menu but it doesn’t work, the app compiles runs just right but when I touch the desired item (about) the app hangs.
I’m using this code to try to call Activitysobre.
Intent iSobre = new Intent(this, ActivitySobre.class);
startActivity(iSobre);
I have already searched and found codes like getActivity(), however that does not work.
Mainactivity.java
private void displaySelectedScreen(int id){
android.support.v4.app.Fragment fragment = null;
switch (id){
case R.id.nav_home:
fragment = new FragmentHome();
break;
case R.id.nav_notificacao:
fragment = new FragmentNotificacao();
break;
case R.id.nav_favorito:
fragment = new FragmentFavoritos();
break;
case R.id.nav_minhaconta:
fragment = new FragmentMinhaConta();
break;
case R.id.nav_share:
fragment = new FragmentSobre();
break;
case R.id.item_sobre:
Intent iSobre = new Intent(this, ActivitySobre.class);
startActivity(iSobre);
//fragment = new FragmentSobre();
break;
}
if(fragment != null){
android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_main, fragment);
ft.commit();
}
Does anyone have any idea how to fix this? Since the Spring.
What happens when you do? Intent iSobre = new Intent(getActivity(), Activitysobre.class); getActivity(). startActivity(iSobre);
– Antonio S. Junior
I’m running the app right on my phone. .
– Rafael Dias
You can pick up the log in android studio in the RUN tab when it gives problem and see exactly what the problem!
– Antonio S. Junior
Okay, just a moment, I’ll do it.
– Rafael Dias
Antonio, I know what the hell happened. I’m about a week trying to make it work and when I went to debug the code it compiled and ran normally. I was able to open Activity.
– Rafael Dias
Strange. ?
– Rafael Dias
Did you modify something in the code? What could happen is that it needs the Parent context so you would have to pass getActivity(). startActivity(iSobre); . If you didn’t touch anything I wouldn’t know what hahaha was. If that was it, you tell me that I put as an answer.
– Antonio S. Junior
The only thing I changed was that it excludes a line of code from Activitysobre.java And I wrote this code from Intent and gave a Clean and a Rebuild. I tried to use the method informed by Voce but unfortunately it didn’t work.
– Rafael Dias
ah blz, but at least it’s working there, right?
– Antonio S. Junior
maybe the mistake was in Activity on and not in the act of opening her
– Igor Oliveira
Really, maybe that was it. Thank you for your help. Thank you very much.
– Rafael Dias