退出后停止刷新页面

Stop going on Refreshed page once we exit

我有两个页面 1.MainActivity 2.Next page.I 正在刷新每 10 页后的下一页 seconds.The 问题是一旦我点击返回并回到主页面 Activity 页面它再次进入下一页,因为它 refreshed.I 不希望它直接转到下一页 page.I 已尝试使用 onBackPressed 按钮,但它不起作用。 以下是我的代码:-

MainActivity.java

public class MainActivity extends Activity {
    Button next;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        next=(Button)findViewById(R.id.refresh);
        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,Next.class);
                startActivity(intent);

            }
        });
    }
}

NextPage.java

public class Next extends Activity {
    ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.next);
        iv=(ImageView)findViewById(R.id.imagev);

         Toast.makeText(Next.this, "Refreshed", Toast.LENGTH_SHORT).show();



        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                Intent intent = getIntent();
                overridePendingTransition(0, 0);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                finish();
                overridePendingTransition(0, 0);
                startActivity(intent);
            }
        }, 10000);




    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.ram.refresh.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:id="@+id/hello"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/refresh"
        android:text="Next page"
        android:layout_below="@+id/hello"/>
</RelativeLayout>

next.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imagev"
        android:src="@drawable/smiley"/>

</LinearLayout>
 @Override
        public void onBackPressed() {
handler.removeCallbacksAndMessages(null);
            finish();
        }

在 onBackPressed 中只有 finish(),删除 super.onBackPressed(); 试试看,让我知道