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

  • SEARCH
  • Home
  • 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 7518543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:45:52+00:00 2026-05-30T01:45:52+00:00

I’m sure I’m doing this inherently wrong, but I figured I’d ask anyway. I

  • 0

I’m sure I’m doing this inherently wrong, but I figured I’d ask anyway. I haven’t seemed to find a strict answer to this, and I’m doing everything answers to questions like this say to do. So, I figure its something to do with Fragments or something. I’m fairly new to Android development, so please bear with me.

So, I have a gallery view. When you click one of the items in this gallery it starts an intent for an Activity that displays that item in a pager with the other items surrounding it. When you click home on the action bar, or hit the back button and then click a different gallery view that does the same thing, the new one loads up fine.

When you hit home, go to another app, and long-hold the home button and hit the app I am, it loads up fine (albeit, not always in the right place which I figure is something I just need to add to savedInstanceState, but I digress..)

However, when I hit the home button. Hit the launcher icon (which starts the mainActivity) and then hit one of the galleries, it shows the OLD one in the activity. This is the problem, and one I could rectify if I could get the activity to start from scratch while maintaining all of the working functionality.

In the XML, the activity is specified as such:

<activity
    android:name=".NewsViewCatActivity"
    android:launchMode="singleTop"
    android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|uiMode"
    android:theme="@style/Theme.BgsuNews" >
    <intent-filter>
        <action android:name="edu.bgsu.news.VIEW_CAT" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

I’m calling the intent as such:

// Launch a News View Activity
Intent myIntent = new Intent(context,
        NewsViewCatActivity.class);
myIntent.putExtra("news", (Serializable)subcat);
myIntent.putExtra("title", catTitle);
myIntent.putExtra("pos", position);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(myIntent);

and the activity calling this new activity/intent is defined as the following:

<activity
    android:name=".NewsActivity"
    android:clearTaskOnLaunch="true"
    android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|uiMode"
    android:label="@string/shortcut_name"
    android:launchMode="singleInstance"
    android:theme="@style/Theme.BgsuNews" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

and my activity itself uses the code below:

package edu.bgsu.news;

import java.io.Serializable;
import java.util.List;

import com.viewpagerindicator.CirclePageIndicator;

import edu.bgsu.news.api.NewsItem;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.MenuInflater;
import android.view.Window;

public class NewsViewCatActivity extends FragmentActivity
{
    private static final String TAG = "BGSUNEWS";

    private ViewPager mViewPager;
    private MyFragmentPagerAdapter mMyFragmentPagerAdapter;
    private CirclePageIndicator mCircleIndicator;
    private List<NewsItem> news;
    private String title;
    private Integer pos;
    private String catID;
    private ActionBar actionBar;

    public void onNewIntent(Intent intent)
    {
        Log.i(TAG, "onNewIntent for NewsCatActivity");
        setIntent(intent);
        loadIt();
    }

    @SuppressWarnings("unchecked")
    private void loadIt()
    {
        news = null;
        Bundle extras = getIntent().getExtras();
        news = (List<NewsItem>) extras.get("news");
        title = (String) extras.get("title");
        pos = (Integer) extras.get("pos");
        catID = (String) extras.get("catID");
        if (mMyFragmentPagerAdapter != null)
            mMyFragmentPagerAdapter.notifyDataSetChanged();
        mViewPager.setCurrentItem(pos);
        actionBar.setTitle(title);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.news_view_menu, menu);
        NewsItem cNews = news.get(mViewPager.getCurrentItem());
        changeMenuItem(menu.findItem(R.id.news_fave), cNews.isFaved());
        return true;
    }

    public void onSaveInstanceState(Bundle savedInstanceState)
    {
        savedInstanceState.putSerializable("news", (Serializable) this.news);
    }

    @SuppressWarnings("unchecked")
    public void onRestoreInstanceState(Bundle savedInstanceState)
    {
        this.news = (List<NewsItem>) savedInstanceState.getSerializable("news");
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        NewsItem cNews;
        switch (item.getItemId())
        {
            case android.R.id.home:
                // app icon in action bar clicked; go home
                Intent intent = new Intent(this, NewsActivity.class);
                intent.putExtra("catID", catID);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
                finish();
                return true;
            case R.id.news_share:
                // Uri uri = Uri.parse(news.getLink());
                cNews = news.get(mViewPager.getCurrentItem());
                Intent sharingIntent = new Intent(
                        android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                        cNews.getName() + " - " + cNews.getLink());
                sharingIntent.putExtra(android.content.Intent.EXTRA_TITLE,
                        cNews.getName());
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                        "Shared: " + cNews.getName());
                startActivity(Intent.createChooser(sharingIntent, "Share "
                        + cNews.getName()));
                return true;
            case R.id.news_fave:
                cNews = news.get(mViewPager.getCurrentItem());
                if (cNews.isFaved())
                {
                    cNews.unFave();
                    Log.i(TAG, "Unfaved it!");
                    changeMenuItem(item, false);
                } else
                {
                    cNews.fave();
                    Log.i(TAG, "Faved it!");
                    changeMenuItem(item, true);
                }
                return true;
            case R.id.news_open:
                Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(news
                        .get(mViewPager.getCurrentItem()).getLink()));
                startActivity(intent1);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    public void changeMenuItem(MenuItem item, boolean isFaved)
    {
        if (isFaved)
        {
            item.setIcon(R.drawable.ic_action_star_hl);
            item.setTitle(R.string.news_unfave);
        } else
        {
            item.setIcon(R.drawable.ic_action_star);
            item.setTitle(R.string.news_fave);
        }
    }

    public void onResume()
    {
        Log.i(TAG, "onResume for NewsCatActivity");

        runViewStuffs();
        loadIt();

        super.onResume();
    }

    public void onCreate(Bundle savedInstanceState)
    {
        Log.i(TAG, "onCreate for NewsCatActivity");
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_multiple_news);
        // onResume called
    }

    public void runViewStuffs()
    {
        actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        mViewPager = (ViewPager) findViewById(R.id.news_pager);
        mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(
                getSupportFragmentManager());
        mViewPager.setAdapter(mMyFragmentPagerAdapter);

        mCircleIndicator = (CirclePageIndicator) findViewById(R.id.news_indicator);
        mCircleIndicator.setViewPager(mViewPager);
        mCircleIndicator.setOnPageChangeListener(new MyPagerListener());
    }

    public class MyPagerListener implements ViewPager.OnPageChangeListener
    {
        @Override
        public void onPageSelected(int position)
        {
            // TODO Grab the menu item and change it.
            invalidateOptionsMenu();
        }

        @Override
        public void onPageScrolled(int position, float positionOffset,
                int positionOffsetPixels)
        {

        }

        @Override
        public void onPageScrollStateChanged(int state)
        {
        }
    }

    private class MyFragmentPagerAdapter extends FragmentPagerAdapter
    {
        public MyFragmentPagerAdapter(FragmentManager fm)
        {
            super(fm);
        }

        @Override
        public Fragment getItem(int index)
        {
            return NewsViewFragment.newInstance(news.get(index),
                    getApplicationContext());
        }

        @Override
        public int getCount()
        {
            return news.size();
        }

        public int getItemPosition(Object obj)
        {
            return news.indexOf(obj);
        }
    }
}

I’m setting the new intent, and calling all the things I normally call, so the way I’m thinking it should “just work” (TM). However, it’s NOT.

So my general question is: how do I force this activity to start FRESH.

and my alternative question is: what am I doing that’s inherently wrong?

I offer my general condolences and excuses for anything that may be perceived as “n00by”

  • 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-05-30T01:45:53+00:00Added an answer on May 30, 2026 at 1:45 am

    If you have a definitive need to restart your activity, override onNewIntent(Intent).

    Call finish, and then create a new intent for the activity.

    • 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'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
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
I am doing a simple coin flipping experiment for class that involves flipping a

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.