Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8321293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:58:03+00:00 2026-06-08T22:58:03+00:00

I’m working on an Android application built with ActionBarSherlock and ViewPagerIndicator with a minSDK

  • 0

I’m working on an Android application built with ActionBarSherlock and ViewPagerIndicator with a minSDK of 8 (Android 2.2) and targetSDK of 16 (Android 4.1) making use of the Android Compatibility Library. I have a messaging portion of the app where messages are stored in a SQLite database and I’m using CommonsWare’s cwac-loaderex to use a cursor loader with the SQLite database. When the activity loads, everything works great and the messages are displayed, but when I rotate the device it just displays a ListFragment with the loading cicle.

Turning on LoaderManager.enableDebugLogging(true) existing loaders are being reused when I rotate, I also tried getSupportLoaderManager().destroyLoader(ID) in onDestroy and new loaders are being created but I still have the same result, a ListFragment with the loading circle. I have tested in both orientations before opening the messaging activity and they both work fine, it’s just an issue when I rotate when the messaging activity is visible. I have also tried going in to the messaging activity in portrait, clicking on a message which takes me to another activity without destroying the messaging activity, changing to landscape and then pressing back to the messaging activity and everything displays fine.

I haven’t been able to figure out why messages are not being displayed after a rotate. I’d be very greatful for any ideas or help. I have included my messaging activity below.

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SimpleCursorAdapter;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.commonsware.cwac.loaderex.acl.SQLiteCursorLoader;
import com.viewpagerindicator.TitlePageIndicator;

import com.lukekorth.DB.DatabaseHelper;
import com.lukekorth.Helpers.MessageFragment;

public class MyMessagesActivity extends SherlockFragmentActivity implements
LoaderManager.LoaderCallbacks<Cursor> {

        private FragmentAdapter mFragmentAdapter;
    private ViewPager mPager;
    private DatabaseHelper mDB;
    private SimpleCursorAdapter mInboxCursorAdapter;
    private SimpleCursorAdapter mArchiveCursorAdapter;

    private MessageFragment[] content = new MessageFragment[2];

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.messages);

        getSupportActionBar().setHomeButtonEnabled(true);
        getSherlock().getActionBar().setDisplayHomeAsUpEnabled(true);

        mDB = new DatabaseHelper(this);

        content[0] = new MessageFragment();
        content[1] = new MessageFragment();

        /////////--------------------///////
        LoaderManager.enableDebugLogging(true);

        mInboxCursorAdapter = new SimpleCursorAdapter(this, R.layout.message_item, null, new String[] { DatabaseHelper.senderName,
                DatabaseHelper.lastUpdate, DatabaseHelper.subject, DatabaseHelper.lastSnippet }, new int[] { R.id.name, R.id.date,
                R.id.subject, R.id.snippet });

        mArchiveCursorAdapter = new SimpleCursorAdapter(this, R.layout.message_item, null, new String[] { DatabaseHelper.senderName,
                DatabaseHelper.lastUpdate, DatabaseHelper.subject, DatabaseHelper.lastSnippet }, new int[] { R.id.name, R.id.date,
                R.id.subject, R.id.snippet });

        content[0].setListAdapter(mInboxCursorAdapter);
        content[1].setListAdapter(mArchiveCursorAdapter);

        getSupportLoaderManager().initLoader(0, null, this);
        getSupportLoaderManager().initLoader(1, null, this);
        ///////////////------------------////////////

        mFragmentAdapter = new FragmentAdapter(getSupportFragmentManager());
        mFragmentAdapter.updateContent(content);

        mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setAdapter(mFragmentAdapter);

        TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.indicator);
        indicator.setViewPager(mPager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        getSupportLoaderManager().destroyLoader(0);
        getSupportLoaderManager().destroyLoader(1);

        mDB.close();
    }

    @Override
    public Loader<Cursor> onCreateLoader(int folder, Bundle arg1) {
        String query = "select " + DatabaseHelper.threads + "." + DatabaseHelper.threadKey + "," + DatabaseHelper.subject +
                "," + DatabaseHelper.archive + "," + DatabaseHelper.otherUser + "," + DatabaseHelper.lastUpdate + "," +
                DatabaseHelper.lastSnippet + "," + DatabaseHelper.senderPicture + "," + DatabaseHelper.senderName + " from " +
                DatabaseHelper.threads + " left join " + DatabaseHelper.senders + " on " + DatabaseHelper.threads + "." +
                DatabaseHelper.otherUser + " = " + DatabaseHelper.senders + "." + DatabaseHelper.senderKey + " where " +
                DatabaseHelper.archive;

        if(folder == 0)
            query += " = 0 order by ";
        else
            query += " = 1 order by ";

        query += DatabaseHelper.lastUpdate + " desc";

        return new SQLiteCursorLoader(this, mDB, query, null);
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        if(loader.getId() == 0)
            mInboxCursorAdapter.swapCursor(cursor);
        else
            mArchiveCursorAdapter.swapCursor(cursor);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        if(loader.getId() == 0)
            mInboxCursorAdapter.swapCursor(null);
        else
            mArchiveCursorAdapter.swapCursor(null);
    }
}

class FragmentAdapter extends FragmentPagerAdapter {
    protected static final String[] TITLE = new String[] { "Inbox", "Archive", };

    private ListFragment[] mContent;

    private int mCount = TITLE.length;

    public FragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    public void updateContent(MessageFragment[] content){
        mContent = content;
    }

    @Override
    public Fragment getItem(int position) {
        return mContent[position % mContent.length];
    }

    @Override
    public int getCount() {
        return mCount;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return FragmentAdapter.TITLE[position % TITLE.length];
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:58:05+00:00Added an answer on June 8, 2026 at 10:58 pm

    It turns out there is some strangeness with ViewPager and fragment tags. My solution was to add the fragments in a transaction in onSaveInstanceState() and then in onCreate() (second piece of code) to get the fragments by tag using the tags generated in the ViewPager. I was able to figure out the tag scheme used from this question. Hope this can save someone a few days work.

    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
    
        ft.add(content[0], content[0].getTag());
        ft.add(content[1], content[1].getTag());
    
        ft.commit();
    }
    
    
    
    
        FragmentManager fm = getSupportFragmentManager();
    
        content[0] = (MessageFragment) fm.findFragmentByTag("android:switcher:"+ R.id.pager + ":0");
        content[1] = (MessageFragment) fm.findFragmentByTag("android:switcher:"+ R.id.pager + ":1");
    
        if(content[0] == null || content[1] == null){
            content[0] = new MessageFragment();
            content[1] = new MessageFragment();
    
            content[0].setListAdapter(mInboxCursorAdapter);
            content[1].setListAdapter(mArchiveCursorAdapter);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.