Android中可以使用Intent传递数据来实现页面跳转,可以通过Intent对象中的getExtras()方法获取传递过来的数据,从而判断是从哪个页面跳转过来的。具体实现步骤如下:

  1. 在源页面中使用Intent.putExtra()方法将数据传递给目标页面。

  2. 在目标页面中使用getIntent()方法获取Intent对象,然后使用getExtras()方法获取传递过来的数据,从而判断源页面的信息。

例如,在MainActivity中跳转到SecondActivity页面,并传递一个字符串参数'fromMain',可以使用以下代码:

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra('from', 'fromMain');
startActivity(intent);

在SecondActivity中获取传递过来的参数,并判断是从哪个页面跳转过来的:

String from = getIntent().getStringExtra('from');
if (from != null && from.equals('fromMain')) {
    // 从MainActivity跳转过来
} else if (from != null && from.equals('fromOther')) {
    // 从其他页面跳转过来
}
Android 页面跳转获取来源页面信息

原文地址: https://www.cveoy.top/t/topic/nFN3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录