Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

Anything that has to do with ActionBar and Tabs is deprecated. Why? and how would i fix this. Android Studio.

The app doesn't run anymore it crashes instantly. I am guessing that the deprecated stuff that has appeared everywhere has something to do with it? Am I right? How do i fix this? NAVIGATION_MODE_TABS, setNavigationMode, setSelectedNavigationItem, .addTab, .newTab,

This is some of it:

'''java

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);


    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());


    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);


    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });


    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {

        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }'''

Ive got this line in the beggining of the Activity:

'''java

public class MainActivity extends ActionBarActivity implements ActionBar.TabListener { '''

ActionBarActivity, .TabListener

Hello,

There have been a lot of API level changes in Android lately. Could you post your code so that we can give you specific help for your issues?

2 Answers

Sorry if this is extremely messy. Getting to know this site.

Hello,

I think I'm understanding which of the deprecations you are running into. One post here on Treehouse where another forum user goes over their fix for the problem can be found here. I have not tried it out personally so I cannot say how well it works, but it looks like you cannot actually click the tabs to navigate. Another option(again, I haven't tried it) that says it preserves clickable tabs is to use the library PagerSlidingTabStrip available on Github. More info on that can be found here on stackoverflow. Let me know if that helps and if you need more assistance.

Well thank you for the fix but I think i found the problem. The loading icon method that Ben added in his Ribbit app doesn´t seem to be supported by Lollipop thus making the app crash just by trying to get it. Could that be right?

Its possible if a method has been removed from the API(which deprecated calls are after a while), that calling that method on a device/emulator could cause it to crash.