спасибо за то, что вы здесь делаете.
У меня есть простое приложение с только Main_Activity и nav_drawers с 12 фрагментами.
Все было безупречно (большое слово), пока я не добавилкоды для показа рекламы.
Часть некоторые ошибки в Gradle.app, когда я добавил 'com.google.android.gms: play-services-ads: 17.0.0' , который создаетнесовпадение с версиями, которое заставило меня использовать // noinspection и т. д.,
---> , теперь ящик больше не работает.Он застрял в главном действии.
---> Почему он больше не работает?Где ошибка?Журнал событий не говорит со мной.Я не изменил предыдущий код.
Это моя MainActivity.java
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
MobileAds.initialize(this,
"ca-app-pub-261529***APP****~****ID****");
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
setTitle("Introduction");
viewIntro fragment = new viewIntro();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Introduction");
fragmentTransaction.commit();
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav_view_intro) {
setTitle("Introduction");
viewIntro fragment = new viewIntro();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Introduction");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_one) {
setTitle("Tablet I");
viewOne fragment = new viewOne();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet I");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_two) {
setTitle("Tablet II");
viewTwo fragment = new viewTwo();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet II");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_three) {
setTitle("Tablet III");
viewThree fragment = new viewThree();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet III");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_four) {
setTitle("Tablet IV");
viewFour fragment = new viewFour();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet IV");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_five) {
setTitle("Tablet V");
viewFive fragment = new viewFive();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet V");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_six) {
setTitle("Tablet VI");
viewSix fragment = new viewSix();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet VI");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_seven) {
setTitle("Tablet VII");
viewSeven fragment = new viewSeven();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet VII");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_eight) {
setTitle("Tablet VIII");
viewEight fragment = new viewEight();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet VIII");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_nine) {
setTitle("Tablet IX");
viewNine fragment = new viewNine();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet IX");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_ten) {
setTitle("Tablet X");
viewTen fragment = new viewTen();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet X");
fragmentTransaction.commit();
} else if (id == R.id.nav_view_eleven) {
setTitle("Tablet XI");
viewEleven fragment = new viewEleven();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment, "Tablet XI");
fragmentTransaction.commit();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
return true;
}
}
XML-часть, которую я добавил для ADS:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-2615***UNIT****/****ID****">