Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Help with ActionBarActivity

I'm trying to use ActionBarActivity in my MainActivity class. When I try to run the app i get this in my logcat:

06-02 09:39:08.686: E/AndroidRuntime(4905): FATAL EXCEPTION: main 06-02 09:39:08.686: E/AndroidRuntime(4905): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jordanpeterson.textly/com.jordanpeterson.textly.ui.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1960) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.app.ActivityThread.access$600(ActivityThread.java:123) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.os.Handler.dispatchMessage(Handler.java:99) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.os.Looper.loop(Looper.java:137) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.app.ActivityThread.main(ActivityThread.java:4429) 06-02 09:39:08.686: E/AndroidRuntime(4905): at java.lang.reflect.Method.invokeNative(Native Method) 06-02 09:39:08.686: E/AndroidRuntime(4905): at java.lang.reflect.Method.invoke(Method.java:511) 06-02 09:39:08.686: E/AndroidRuntime(4905): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:3151) 06-02 09:39:08.686: E/AndroidRuntime(4905): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:2918) 06-02 09:39:08.686: E/AndroidRuntime(4905): at dalvik.system.NativeStart.main(Native Method) 06-02 09:39:08.686: E/AndroidRuntime(4905): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59) 06-02 09:39:08.686: E/AndroidRuntime(4905): at com.jordanpeterson.textly.ui.MainActivity.onCreate(MainActivity.java:191) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.app.Activity.performCreate(Activity.java:4471) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 06-02 09:39:08.686: E/AndroidRuntime(4905): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924) 06-02 09:39:08.686: E/AndroidRuntime(4905): ... 11 more

Does anybody know how to fix this?

Here is my styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="Theme.Textly" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarItemBackground">@drawable/selectable_background_textly</item>
    <item name="android:popupMenuStyle">@style/PopupMenu.Textly</item>
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Textly</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Textly</item>
    <item name="android:actionDropDownStyle">@style/DropDownNav.Textly</item>
    <item name="android:actionBarStyle">@style/ActionBar.Solid.Textly</item>
    <item name="android:actionModeBackground">@drawable/cab_background_top_textly</item>
    <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_textly</item>
    <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Textly</item>
    <item name="android:editTextBackground">@drawable/apptheme_edit_text_holo_light</item>
    <item name="android:imageButtonStyle">@style/ImageButtonAppTheme</item>
    <item name="android:listViewStyle">@style/Theme.Textly.LightBlueBackground</item>
    <item name="android:gridViewStyle">@style/Theme.Textly.LightBlueBackground</item>
</style>





<style name="Theme.Textly.LightBlueBackground">
    <item name="android:background">@color/light_blue_background</item>
    <item name="android:divider">@null</item>
</style>


<style name="ActionBar.Solid.Textly" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
    <item name="android:background">@drawable/ab_solid_textly</item>
    <item name="android:backgroundStacked">@drawable/ab_stacked_solid_textly</item>
    <item name="android:backgroundSplit">@drawable/ab_bottom_solid_textly</item>
    <item name="android:progressBarStyle">@style/ProgressBar.Textly</item>
</style>

<style name="ActionBar.Transparent.Textly" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@drawable/ab_transparent_textly</item>
    <item name="android:progressBarStyle">@style/ProgressBar.Textly</item>
</style>

<style name="PopupMenu.Textly" parent="@android:style/Widget.Holo.Light.ListPopupWindow">
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_textly</item>
</style>

<style name="DropDownListView.Textly" parent="@android:style/Widget.Holo.Light.ListView.DropDown">
    <item name="android:listSelector">@drawable/selectable_background_textly</item>
</style>

<style name="ActionBarTabStyle.Textly" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator_ab_textly</item>
</style>

<style name="DropDownNav.Textly" parent="@android:style/Widget.Holo.Light.Spinner">
    <item name="android:background">@drawable/spinner_background_ab_textly</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_textly</item>
    <item name="android:dropDownSelector">@drawable/selectable_background_textly</item>
</style>

<style name="ProgressBar.Textly" parent="@android:style/Widget.Holo.Light.ProgressBar.Horizontal">
    <item name="android:progressDrawable">@drawable/progress_horizontal_textly</item>
</style>

<style name="ActionButton.CloseMode.Textly" parent="@android:style/Widget.Holo.Light.ActionButton.CloseMode">
    <item name="android:background">@drawable/btn_cab_done_textly</item>
</style>

<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Textly.Widget" parent="@android:style/Theme.Holo">
    <item name="android:popupMenuStyle">@style/PopupMenu.Textly</item>
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Textly</item>
</style>

<style name="ImageButtonAppTheme" parent="android:Widget.Holo.Light.ImageButton">
    <item name="android:background">@drawable/apptheme_btn_default_holo_light</item>
</style>

<style name="AuthBackgroundImage">
    <item name="android:scaleType">fitXY</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:layout_alignParentLeft">true</item>
    <item name="android:layout_alignParentTop">true</item>
    <item name="android:src">@drawable/background</item>
</style>

<style name="AuthTitle" parent="android:Widget.TextView">
    <item name="android:layout_marginTop">32dp</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:textSize">60sp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_alignParentTop">true</item>
    <item name="android:layout_centerHorizontal">true</item>
    <item name="android:text">@string/app_name</item>
</style>

<style name="styleName">
    <item name="android:background">@android:color/white</item>
    <item name="android:layout_marginLeft">@dimen/activity_horizontal_margin</item>
    <item name="android:layout_marginRight">@dimen/activity_horizontal_margin</item>
    <item name="android:layout_marginTop">@dimen/login_vertical_margin</item>
    <item name="android:orientation">vertical</item>
    <item name="android:paddingBottom">@dimen/login_vertical_margin</item>
    <item name="android:paddingLeft">@dimen/login_horizontal_padding</item>
    <item name="android:paddingRight">@dimen/login_horizontal_padding</item>
    <item name="android:paddingTop">@dimen/login_vertical_margin</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_below">@id/title</item>
</style>

<style name="AuthEditText" parent="android:Widget.Holo.Light.EditText">
    <item name="android:ems">10</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textSize">17sp</item>
    <item name="android:textColorHint">@color/light_gray</item>
</style>

<style name="AuthButton" parent="android:Widget.Button">
    <item name="android:background">@drawable/button_custom</item>
    <item name="android:layout_marginLeft">@dimen/activity_horizontal_margin</item>
    <item name="android:layout_marginRight">@dimen/activity_horizontal_margin</item>
    <item name="android:textColor">@color/text_color</item>
    <item name="android:textSize">13sp</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:text">@string/login_button_label</item>
</style>

<style name="GridImage">
    <item name="android:adjustViewBounds">true</item>
    <item name="android:scaleType">fitXY</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_alignParentRight">true</item>
   <item name="android:layout_alignParentTop">true</item>
</style>

</resources>

3 Answers

Alejandro Crespo
Alejandro Crespo
6,628 Points

ActionBarActivity is deprecated. If you want an Action Bar you'll need to set up a toolbar and all the good stuff an ActionBar entails. Here is a super good link, so you can update your code.. Extend your MainActivity with the AppCompatActivity, its all the hype nowadays. If you don't need an ActionBar, then disregard the link, just don't use ActionBarActivity and extend AppCompatActivity and it should fix your problem http://www.exoguru.com/android/material-design/navigation/android-sliding-tabs-with-material-design.html

Hi, Thank you for helping me. I changed my activity to extends AppCompatActivity. I am now getting the following error.

06-02 11:23:46.279: E/AndroidRuntime(3501): FATAL EXCEPTION: main 06-02 11:23:46.279: E/AndroidRuntime(3501): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jordanpeterson.textly/com.jordanpeterson.textly.ui.MainActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1960) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.app.ActivityThread.access$600(ActivityThread.java:123) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.os.Handler.dispatchMessage(Handler.java:99) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.os.Looper.loop(Looper.java:137) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.app.ActivityThread.main(ActivityThread.java:4429) 06-02 11:23:46.279: E/AndroidRuntime(3501): at java.lang.reflect.Method.invokeNative(Native Method) 06-02 11:23:46.279: E/AndroidRuntime(3501): at java.lang.reflect.Method.invoke(Method.java:511) 06-02 11:23:46.279: E/AndroidRuntime(3501): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:3151) 06-02 11:23:46.279: E/AndroidRuntime(3501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:2918) 06-02 11:23:46.279: E/AndroidRuntime(3501): at dalvik.system.NativeStart.main(Native Method) 06-02 11:23:46.279: E/AndroidRuntime(3501): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content 06-02 11:23:46.279: E/AndroidRuntime(3501): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:211) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.app.Activity.requestWindowFeature(Activity.java:3089) 06-02 11:23:46.279: E/AndroidRuntime(3501): at com.jordanpeterson.textly.ui.MainActivity.onCreate(MainActivity.java:192) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.app.Activity.performCreate(Activity.java:4471) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 06-02 11:23:46.279: E/AndroidRuntime(3501): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924) 06-02 11:23:46.279: E/AndroidRuntime(3501): ... 11 more

Alejandro Crespo
Alejandro Crespo
6,628 Points

According to your log you have a requestFeature() you're invoking incorrectly. Make sure you call it before setContentView() or super.onCreate()

Hi Alejandro, Thanks again for helping me I really appreciate it! I'm now getting another error in my logcat.

06-02 12:42:24.503: E/AndroidRuntime(10125): FATAL EXCEPTION: main 06-02 12:42:24.503: E/AndroidRuntime(10125): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jordanpeterson.textly/com.jordanpeterson.textly.ui.MainActivity}: java.lang.ClassCastException: android.support.v7.internal.widget.ContentFrameLayout cannot be cast to android.support.v7.internal.widget.NativeActionModeAwareLayout 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1960) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1985) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.app.ActivityThread.access$600(ActivityThread.java:123) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.os.Handler.dispatchMessage(Handler.java:99) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.os.Looper.loop(Looper.java:137) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.app.ActivityThread.main(ActivityThread.java:4429) 06-02 12:42:24.503: E/AndroidRuntime(10125): at java.lang.reflect.Method.invokeNative(Native Method) 06-02 12:42:24.503: E/AndroidRuntime(10125): at java.lang.reflect.Method.invoke(Method.java:511) 06-02 12:42:24.503: E/AndroidRuntime(10125): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:3151) 06-02 12:42:24.503: E/AndroidRuntime(10125): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:2918) 06-02 12:42:24.503: E/AndroidRuntime(10125): at dalvik.system.NativeStart.main(Native Method) 06-02 12:42:24.503: E/AndroidRuntime(10125): Caused by: java.lang.ClassCastException: android.support.v7.internal.widget.ContentFrameLayout cannot be cast to android.support.v7.internal.widget.NativeActionModeAwareLayout 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.support.v7.app.AppCompatDelegateImplV11.onSubDecorInstalled(AppCompatDelegateImplV11.java:44) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:405) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106) 06-02 12:42:24.503: E/AndroidRuntime(10125): at com.jordanpeterson.textly.ui.MainActivity.onCreate(MainActivity.java:194) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.app.Activity.performCreate(Activity.java:4471) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 06-02 12:42:24.503: E/AndroidRuntime(10125): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1924) 06-02 12:42:24.503: E/AndroidRuntime(10125): ... 11 more

Here is my MainActivity file

import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale;

import android.app.ActionBar; import android.app.AlertDialog; import android.app.FragmentTransaction; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.view.ViewPager; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.Window; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast;

import com.jordanpeterson.textly.R; import com.jordanpeterson.textly.adapters.SectionsPagerAdapter; import com.jordanpeterson.textly.utils.ParseConstants; import com.parse.ParseAnalytics; import com.parse.ParseUser;

public class MainActivity extends AppCompatActivity implements ActionBar.TabListener {

public static final String TAG = MainActivity.class.getSimpleName();

// TODO Shortcut to the top
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private String mActivityTitle;
private ListView mDrawerList;
private ArrayAdapter<String> mAdapter;

public static final int TAKE_PHOTO_REQUEST = 0;
public static final int TAKE_VIDEO_REQUEST = 1;
public static final int PICK_PHOTO_REQUEST = 2;
public static final int PICK_VIDEO_REQUEST = 3;

public static final int MEDIA_TYPE_IMAGE = 4;
public static final int MEDIA_TYPE_VIDEO = 5;

public static final int FILE_SIZE_LIMIT = 1024 * 1024 * 10; // 10 MB

protected Uri mMediaUri;

protected DialogInterface.OnClickListener mDialogListener = new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
        case 0: // Take picture
            Intent takePhotoIntent = new Intent(
                    MediaStore.ACTION_IMAGE_CAPTURE);
            mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
            if (mMediaUri == null) {
                // display an error
                Toast.makeText(MainActivity.this,
                        R.string.error_external_storage, Toast.LENGTH_LONG)
                        .show();
            } else {
                takePhotoIntent
                        .putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
                startActivityForResult(takePhotoIntent, TAKE_PHOTO_REQUEST);
            }
            break;
        case 1: // Take video
            Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
            if (mMediaUri == null) {
                // display an error
                Toast.makeText(MainActivity.this,
                        R.string.error_external_storage, Toast.LENGTH_LONG)
                        .show();
            } else {
                videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
                videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
                videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); // 0
                                                                            // =
                                                                            // lowest
                                                                            // res
                startActivityForResult(videoIntent, TAKE_VIDEO_REQUEST);
            }
            break;
        case 2: // Choose picture
            Intent choosePhotoIntent = new Intent(Intent.ACTION_GET_CONTENT);
            choosePhotoIntent.setType("image/*");
            startActivityForResult(choosePhotoIntent, PICK_PHOTO_REQUEST);
            break;
        case 3: // Choose video
            Intent chooseVideoIntent = new Intent(Intent.ACTION_GET_CONTENT);
            chooseVideoIntent.setType("video/*");
            Toast.makeText(MainActivity.this,
                    R.string.video_file_size_warning, Toast.LENGTH_LONG)
                    .show();
            startActivityForResult(chooseVideoIntent, PICK_VIDEO_REQUEST);
            break;
        }
    }

    private Uri getOutputMediaFileUri(int mediaType) {
        // To be safe, you should check that the SDCard is mounted
        // using Environment.getExternalStorageState() before doing this.
        if (isExternalStorageAvailable()) {
            // get the URI

            // 1. Get the external storage directory
            String appName = MainActivity.this.getString(R.string.app_name);
            File mediaStorageDir = new File(
                    Environment
                            .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                    appName);

            // 2. Create our subdirectory
            if (!mediaStorageDir.exists()) {
                if (!mediaStorageDir.mkdirs()) {
                    Log.e(TAG, "Failed to create directory.");
                    return null;
                }
            }

            // 3. Create a file name
            // 4. Create the file
            File mediaFile;
            Date now = new Date();
            String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
                    Locale.US).format(now);

            String path = mediaStorageDir.getPath() + File.separator;
            if (mediaType == MEDIA_TYPE_IMAGE) {
                mediaFile = new File(path + "IMG_" + timestamp + ".jpg");
            } else if (mediaType == MEDIA_TYPE_VIDEO) {
                mediaFile = new File(path + "VID_" + timestamp + ".mp4");
            } else {
                return null;
            }

            Log.d(TAG, "File: " + Uri.fromFile(mediaFile));

            // 5. Return the file's URI
            return Uri.fromFile(mediaFile);
        } else {
            return null;
        }
    }

    private boolean isExternalStorageAvailable() {
        String state = Environment.getExternalStorageState();

        if (state.equals(Environment.MEDIA_MOUNTED)) {
            return true;
        } else {
            return false;
        }
    }
};

/**
 * The {@link android.support.v4.view.PagerAdapter} that will provide
 * fragments for each of the sections. We use a
 * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
 * will keep every loaded fragment in memory. If this becomes too memory
 * intensive, it may be best to switch to a
 * {@link android.support.v4.app.FragmentStatePagerAdapter}.
 */
SectionsPagerAdapter mSectionsPagerAdapter;

/**
 * The {@link ViewPager} that will host the section contents.
 */
ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);


    // TODO Shortcut to onCreate()

    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mActivityTitle = getTitle().toString();

    addDrawerItems();

// setupDrawer();

// getSupportActionBar().setDisplayHomeAsUpEnabled(true); // getSupportActionBar().setHomeButtonEnabled(true);

    ParseAnalytics.trackAppOpened(getIntent());

    ParseUser currentUser = ParseUser.getCurrentUser();
    if (currentUser == null) {
        navigateToLogin();
    } else {
        Log.i(TAG, currentUser.getUsername());
    }

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(this,
            getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager
            .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
                @Override
                public void onPageSelected(int position) {
                    actionBar.setSelectedNavigationItem(position);
                }
            });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(actionBar.newTab()
                .setIcon(mSectionsPagerAdapter.getIcon(i))
                .setTabListener(this));
    }

}

private void addDrawerItems() {
    String[] osArray = { "Home", "Inbox", "Credits", "GIFS/Stickers", "Settings" };
    mAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, osArray);
    mDrawerList.setAdapter(mAdapter);

    mDrawerList
            .setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    Toast.makeText(MainActivity.this,
                            "Time for an upgrade!", Toast.LENGTH_SHORT)
                            .show();
                }
            });
}

// private void setupDrawer() { // mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, // R.string.drawer_open, R.string.drawer_close) { // // /** Called when a drawer has settled in a completely open state. / // public void onDrawerOpened(View drawerView) { // } // // /* Called when a drawer has settled in a completely closed state. */ // public void onDrawerClosed(View view) { // } // }; // }

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) {
        if (requestCode == PICK_PHOTO_REQUEST
                || requestCode == PICK_VIDEO_REQUEST) {
            if (data == null) {
                Toast.makeText(this, getString(R.string.general_error),
                        Toast.LENGTH_LONG).show();
            } else {
                mMediaUri = data.getData();
            }

            Log.i(TAG, "Media URI: " + mMediaUri);
            if (requestCode == PICK_VIDEO_REQUEST) {
                // make sure the file is less than 10 MB
                int fileSize = 0;
                InputStream inputStream = null;

                try {
                    inputStream = getContentResolver().openInputStream(
                            mMediaUri);
                    fileSize = inputStream.available();
                } catch (FileNotFoundException e) {
                    Toast.makeText(this, R.string.error_opening_file,
                            Toast.LENGTH_LONG).show();
                    return;
                } catch (IOException e) {
                    Toast.makeText(this, R.string.error_opening_file,
                            Toast.LENGTH_LONG).show();
                    return;
                } finally {
                    try {
                        inputStream.close();
                    } catch (IOException e) { /* Intentionally blank */
                    }
                }

                if (fileSize >= FILE_SIZE_LIMIT) {
                    Toast.makeText(this,
                            R.string.error_file_size_too_large,
                            Toast.LENGTH_LONG).show();
                    return;
                }
            }
        } else {
            Intent mediaScanIntent = new Intent(
                    Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            mediaScanIntent.setData(mMediaUri);
            sendBroadcast(mediaScanIntent);
        }

        Intent recipientsIntent = new Intent(this, RecipientsActivity.class);
        recipientsIntent.setData(mMediaUri);

        String fileType;
        if (requestCode == PICK_PHOTO_REQUEST
                || requestCode == TAKE_PHOTO_REQUEST) {
            fileType = ParseConstants.TYPE_IMAGE;
        } else {
            fileType = ParseConstants.TYPE_VIDEO;
        }

        recipientsIntent.putExtra(ParseConstants.KEY_FILE_TYPE, fileType);
        startActivity(recipientsIntent);
    } else if (resultCode != RESULT_CANCELED) {
        Toast.makeText(this, R.string.general_error, Toast.LENGTH_LONG)
                .show();
    }
}

private void navigateToLogin() {
    Intent intent = new Intent(this, LoginActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();

    switch (itemId) {
    case R.id.action_logout:
        ParseUser.logOut();
        navigateToLogin();
        break;
    case R.id.action_edit_friends:
        Intent intent = new Intent(this, EditFriendsActivity.class);
        startActivity(intent);
        break;
    case R.id.action_camera:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setItems(R.array.camera_choices, mDialogListener);
        AlertDialog dialog = builder.create();
        dialog.show();
        break;
    case R.id.action_sms:
        Intent smsIntent = new Intent(this, SendSMSActivity.class);
        startActivity(smsIntent);
        break;
    case R.id.action_message:
        Intent messageIntent = new Intent(this, SendTextActivity.class);
        startActivity(messageIntent);
        break;

    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onTabSelected(ActionBar.Tab tab,
        FragmentTransaction fragmentTransaction) {
    // When the given tab is selected, switch to the corresponding page in
    // the ViewPager.
    mViewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(ActionBar.Tab tab,
        FragmentTransaction fragmentTransaction) {
}

@Override
public void onTabReselected(ActionBar.Tab tab,
        FragmentTransaction fragmentTransaction) {
}

}

Alejandro Crespo
Alejandro Crespo
6,628 Points

Nah, bro. ActionBar and all its methods are deprecated, you're using old code that doesn't work everytime you call actionBar. I see you're trying to set up tabs, you can't do it like that anymore, check out the link i sent you. Also, forget about the WINDOWREQUEST just use a progressbar and remember to set its visibility.

Alejandro Crespo
Alejandro Crespo
6,628 Points

Seriously, check out the link, man, you'll save yourself a headache.