简体   繁体   English

如何检查是否创建了Intent

[英]How can i check if a Intent was created

I want to check at the beginning of my App if an Intent exists. 我想检查我的应用程序的开头是否存在Intent So when I launch it some details are displayed. 因此,当我启动它时,会显示一些详细信息。 I can then switch to a different class to edit those details. 然后,我可以切换到其他班级来编辑这些详细信息。 Now if i switch back to my Main class I want the details to be replaced with the ones I just edited. 现在,如果我切换回我的主类,我希望将这些细节替换为我刚刚编辑的细节。 I hope you guys can help me out and hopefully you understand my question. 我希望你们能帮助我,希望您能理解我的问题。

protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_dashboard);

     if (getIntent()!= null) {
         Intent myintent2 = getIntent();
         ArrayList<String> buffer = new ArrayList<>();
         buffer = myintent2.getStringArrayListExtra("Interest_items");
         for (int f = 0; f < buffer.size(); f++) {
             Interests.add(buffer.get(f));
         }
     } else {
         Interests.add("Cycling");
         Interests.add("Swimming");
         Interests.add ("Running");
     }
}

You can use a boolean . 您可以使用boolean

First define a boolean as false above onCreate part 首先在onCreate部分上方将boolean定义为false

Then change its value to true in the intent body 然后在intent主体中将其值更改为true

Now you can write an if control sentence to find that the desired intent has already executed or not 现在,您可以编写一个if控制语句来查找所需的intent是否已经执行

Another way is correcting your code like this: 另一种方法是像这样更正您的代码:

if (getIntent().getStringArrayListExtra("Interest_items"))!= null)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查是否有意图发送的捆绑包? - How can I check if there is a bundle sent with the intent? 如何使Intent.createChooser()创建的对话框可取消? - How can I make dialog created by Intent.createChooser() cancelable? Android-如何检查“ stopService”意图的发送者类? - Android - How can I check the sender class of the “stopService” Intent? 如何检查活动中收到的未决意图? - how can I check the pending intent is received in an activity? 如何发送Android意向以将当前笔记保存在evernote中,以便可以使用其他意向创建新笔记? - How do I sent an Android intent to save the current note in evernote so that a new one can created with another intent? 如何检查 Android 服务是否可以处理意图? - How to check if an intent can be handled by an Android service? 如何将对象从创建的意图返回到调用它的方法? - How can I return an object from a created intent back to the method which called it? 如何关闭从Intent.Action Pick创建的对话框以获取图库图像? - How can i dismiss the dialog created from Intent.Action Pick to get Gallery images? 如果未创建Geofire,如何检查Geofire以注销用户? - How can I check Geofire to log user out if no Geofire was created? 我如何注册该意图? - How can I register for this Intent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM