Stack Exchange
Fragment ViewPagerIndicator cannot finish when open new activity
Im use ViewPagerIndicator in SplashActivity, Running automatic with Toast to show position & 1 Button to open MainActivity but Toast cannot stop or Activity not finish after open MainActivity. Can you help me to this problem. Thanks in advance
public class SplashActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);

        mAdapter = new SplashFragmentAdapter(getSupportFragmentManager());
        mPager = (ViewPager) findViewById(R.id.pager);

        mPager.setAdapter(mAdapter);

        mIndicator = (LinePageIndicator) findViewById(R.id.indicator);
        mIndicator.setViewPager(mPager);

        final Handler handler = new Handler();
        final Runnable Update = new Runnable() {
            public void run() {
                if (currentPage == 4) {
                    currentPage = 0;
                }
                mPager.setCurrentItem(currentPage++, true);
            }
        };

        swipeTimer = new Timer();
        swipeTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            handler.post(Update);
            }
        }, 1000, 5000);

        mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                // TODO Auto-generated method stub
                Toast.makeText(SplashActivity.this, "Changed to page " + position, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPageScrollStateChanged(int state) {
                // TODO Auto-generated method stub

            }
        });   

        Button bEnter = (Button) findViewById(R.id.btn_enter);
        bEnter.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent main = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(main);
                finish();
            }
        });
    }
}


why are you using getApplicationContext() to start an activity?

It's Okey, I think getApplicationContext same with SplashActivity.this , so how to resolve it?

try removeCallbacks when your activity destroyed

handler.removeCallbacks(Update); in your onDestroy() method

sorry long reply. I've tried it but not work.
