gpt4 book ai didi

android - 使用 Intent.FLAG_ACTIVITY_SINGLE_TOP 和 CLEAR_TOP 时没有通过额外功能

转载 作者:行者123 更新时间:2023-11-29 23:56:33 26 4
gpt4 key购买 nike

doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if(!imgUriList.isEmpty())
{
Intent intent = new Intent(getBaseContext(), createAdActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imgUriList);
startActivity(intent);


}
}
});

This is the code I have used in my second activity to send extras to the first activity.

I want to keep the first activity as it is when coming back from the second activity. Therefore I have used _SINGLE_TOP,CLEAR_TOP FLAGS.

Without the Flags it works well. But After using the extras extras become null. This is the Code I have used in my first activity.

 @Override
protected void onResume() {
super.onResume();
Toast.makeText(this,"IN RESUME ",Toast.LENGTH_LONG).show();
imageUris = getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if(getIntent().hasExtra(Intent.EXTRA_STREAM)) {
if (!imageUris.isEmpty()) {
createAdViewPagerAdapter viewpager = new createAdViewPagerAdapter(this,imageUris);
photoViewer.setAdapter(viewpager);
}
}
}

Since the first activity also uses some extras sent from MainActivity I have overrides the onNewIntent()method as well.

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
}

最佳答案

使用 getIntent(),您将获得旧的 Intent,您需要处理 onNewIntent() 的 intent 参数。您可以使用 setIntent(intent) 它将更改 getIntent() 返回的 Intent 。要确保对 getIntent() 的任何进一步调用将返回最新的 Intent ,请使用 setIntent().

 @Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
// Do further stuff here
}

关于android - 使用 Intent.FLAG_ACTIVITY_SINGLE_TOP 和 CLEAR_TOP 时没有通过额外功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50317095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com