Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在ANDROID中解析意图_Java_Android_Parsing_Android Intent - Fatal编程技术网

Java 在ANDROID中解析意图

Java 在ANDROID中解析意图,java,android,parsing,android-intent,Java,Android,Parsing,Android Intent,我在Main_Screen.class上有以下代码: add_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent add_user = new Intent(Main_Screen.this, Add_Update_User.class);

我在Main_Screen.class上有以下代码:

    add_btn.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
            Intent add_user = new Intent(Main_Screen.this, Add_Update_User.class);
            add_user.putExtra("called", "add");
            add_user.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(add_user);
            finish();
        }
    });
add_user.putExtra("USERID", "the id of the user you want to put");
我的理解是,我正在向“Add\u Update\u User.class”发送存储在“called”中的字符串“Add”和标志

add_user.putExtra("USERID", "the id of the user you want to put");
现在,我在“Add\u Update\u User.class”中有以下代码:

add_user.putExtra("USERID", "the id of the user you want to put");
我在“Add_Update_User.class”中理解的是,我从意图中的“Main_Screen.class”中获取发送的值,将值“Add”存储在字符串“called_from”中,然后将“called from”与字符串“Add”进行比较“如果比较为真,则视图可见并消失,但如果不是真的,则设置视图的可见度,我的问题是:

add_user.putExtra("USERID", "the id of the user you want to put");
这部分代码到底是什么意思

    USER_ID = Integer.parseInt(getIntent().getStringExtra("USER_ID"));
add_user.putExtra("USERID", "the id of the user you want to put");
实际上,您正在通过Intent将“添加”值从主屏幕发送给添加更新用户

add_user.putExtra("USERID", "the id of the user you want to put");
您所指向的行是相同的,只是您正在提取一个用户id,它是一个字符串。但是,变量USER_ID可能是“int”类型

add_user.putExtra("USERID", "the id of the user you want to put");
因此,你应该在你的主屏幕的某个地方

add_user.putExtra("USERID", "the id of the user you want to put");
你可以用它取回它

add_user.putExtra("USERID", "the id of the user you want to put");
 getIntent().getStringExtra("USER_ID")
然后将字符串解析为一个整数,以将用户id的类型与integer.parseInt(…)匹配

add_user.putExtra("USERID", "the id of the user you want to put");

因此,您需要问自己的真正问题是,为什么您没有函数add_user.putExtra(“user_ID”),如果您不需要它,那么您可以删除您关心的行。

我有您说的那部分,让我来编辑问题。但现在我知道那部分代码到底是怎么回事了。谢谢:戴帽子的钥匙偶尔会卡住?不,不会。为什么?
add_user.putExtra("USERID", "the id of the user you want to put");