安卓;如何在一个 Activity 中初始化状态,然后进行另一项刷新?

标签 android android-2.2-froyo android-lifecycle

我有两项 Activity

第一个从内容提供商获取一些数据,并显示它

第二个 Activity 有一个按钮,单击时应调用第一个 Activity 进行“刷新”,换句话说,从内容提供程序重新加载数据

这是我的第一个 Activity

...
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         setContentView(R.layout.contactsview);
            // Grab data and put it onto screen
                getDataAndPutToUI();
    }

    @Override
    public void onStart()
    {
       //Refresh data
           getDataAndPutToUI();
    }
...

这是我的第二项 Activity

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

        Button button = (Button) findViewById(R.id.intentButton);
            button.setOnClickListener(this);

    }   

    // This is bound to the "refresh" button
    @Override
    public void onClick(View v) {
        // Call first activity, to reload the contacts
        Intent i = new Intent(this, FirstActivity.class);
        startActivity(i);

    }

这是实现此类功能的正确方法吗?感觉不正确,但我无法确定任何理由来支持我的主张

最佳答案

你可以通过根据你的 Intent 设置标志来做到这一点 尝试如下,遍历其他标志

Intent i = new Intent();
                            i.setClass(this, Rss_Feed.class);
//                          i.setClass(Rss_Feed.this, Bru_Maps.class);
                            i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

关于安卓;如何在一个 Activity 中初始化状态,然后进行另一项刷新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3750776/

相关文章:

android - sass : node_modules/ionic-angular/themes/ionic. 函数.scss

android - 在 Android 的许多 fragment 中监控互联网连接

jquery-mobile - 更正 'PhoneGap + jQuery Mobile' 应用程序中的事件注册

java - Android BluetoothSocket - 超时

java - android中变量的全局声明

android - 在 api 级别 8 中替代 setAlpha

java - 为什么从 ViewModel 进行调用时,Retrofit enqueue 不起作用?

android - Firebase API 和 Android 的 Activity 生命周期

android - fragment : what is the best place to measure Views?

java - picasso 无法在 StorageReference 的 onSuccess 方法中加载图像