1

我有一个搜索按钮。

当我点击它时,我想将当前活动的值发送到另一个活动(在我的例子中是 ProductActivity)

这是搜索按钮的代码

 Button nextActivity = (Button) findViewById(R.id.btnSearch);
                nextActivity.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View view) {
                        TextView tvFileNumber = (TextView)findViewById(R.id.tv1);
                        Spinner spAttachement = (Spinner)findViewById(R.id.spinner1) ;
                        Spinner spExecution = (Spinner)findViewById(R.id.spinner2) ;
                        Spinner spCategory = (Spinner)findViewById(R.id.spinner3) ;
                        Spinner spOperation = (Spinner)findViewById(R.id.spinner4) ;
                        Spinner spCollection = (Spinner)findViewById(R.id.spinner5) ;

                        SpinnerData daAttachement =(SpinnerData)spAttachement.getItemAtPosition(spAttachement.getSelectedItemPosition());
                        SpinnerData daExecution =(SpinnerData)spAttachement.getItemAtPosition(spExecution.getSelectedItemPosition());
                        SpinnerData daCategory =(SpinnerData)spAttachement.getItemAtPosition(spCategory.getSelectedItemPosition());
                        SpinnerData daOperation =(SpinnerData)spAttachement.getItemAtPosition(spOperation.getSelectedItemPosition());
                        SpinnerData daCollection =(SpinnerData)spAttachement.getItemAtPosition(spCollection.getSelectedItemPosition());

                        Intent myIntent = new Intent(view.getContext(), ProductActivity.class);
                        //myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        myIntent.putExtra("col_id",6);
                        myIntent.putExtra("site_id",site_id);
                        myIntent.putExtra("brand_id",brand_id);
                        myIntent.putExtra("attachement_id",daAttachement.getValue());
                        myIntent.putExtra("execution_id",daExecution.getValue());
                        myIntent.putExtra("operation_id",daOperation.getValue());
                        myIntent.putExtra("category_id",daCategory.getValue());
                        startActivity(myIntent);

                    }
                });

在我的产品活动中

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_product);
        Intent myIntent= getIntent(); 
        int brand_id = myIntent.getIntExtra("brand_id", 0); 
        int col_id = myIntent.getIntExtra("col_id", 0); 
        int site_id = myIntent.getIntExtra("site_id", 0); 
        int attachement_id = myIntent.getIntExtra("attachement_id", -1); 
        int execution_id = myIntent.getIntExtra("execution_id", -1); 
        int category_id = myIntent.getIntExtra("category_id", -1); 
        int operation_id = myIntent.getIntExtra("operation_id", -1); 
        int eol = myIntent.getIntExtra("eol", -1); 

        Log.v("TESTCOLLECTION",Integer.toString(col_id));

结果显示TESTCOLLECTION
的日志结果:0

在我的示例中,它假设为 6myIntent.putExtra("col_id",6);

请帮忙。我尝试了很多东西,但没有找到原因。

非常感谢。

4

1 回答 1

0

您的活动启动模式似乎是singleTask或类似的,如果是这种情况,您必须覆盖onNewIntent(Intent intent).

这是因为onCreate()只有在创建活动实例时才会调用一次,onNewIntent()才会调用后记。

于 2013-02-19T22:54:29.343 回答