本文介绍了活动重启时如何将意向额外信息传递给onactivityresult?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个android应用程序.需要传递int值.我有一个包含上下文菜单的列表视图.我必须启动Intent.Action_Call.当我开始我的意图时.我的应用程序将进入后台.当意图完成后,我的应用程序开始调查.我的问题是;我没有得到用户的点击位置.我尝试插入到putExtra,但是在onActivityResult中,void不接受我的用户的点击位置的值,并且该值变为零.我可以得到吗?

I am writing an android application. Need to pass int value.I have a listview that it has contextmenu.I must start Intent.Action_Call. When I start my intent. My application is going to background. When intent is finish my application start a survey.My problem is ;I am not getting user"s clicked position.I tried insert to putExtra but in onActivityResult void does not accepted value of my user"s clicked position and value become zero.How can I get ıt ?

   public boolean onContextItemSelected(MenuItem item) {
            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

        selectedPosition = info.position;

     //in here , this value is true.
            Toast.makeText(AnaMenu.this, String.valueOf(selectedPosition), Toast.LENGTH_LONG).show();

            switch (item.getItemId()) {
                case MENU_Ara:

                    Intent i = getIntent();
                    final ArrayList<String> secilmis = i.getStringArrayListExtra("listem");

                    Intent ara = new Intent(Intent.ACTION_CALL);
                    ara.setData(Uri.parse("tel:" + secilmis.get(info.position).toString()));


                    ara.putExtra("selected", selectedPosition);





                    startActivityForResult(ara, AnketDegerlendirmesi);






                    return true;
            }


            return super.onContextItemSelected(item);
        }




     protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {

            if (requestCode == AnketDegerlendirmesi){
                Toast.makeText(AnaMenu.this,String.valueOf(selectedPosition),Toast.LENGTH_LONG).show();

                final AlertDialog.Builder  mBuilder = new AlertDialog.Builder(AnaMenu.this);
                mBuilder.setTitle("Deger");
                mBuilder.setIcon(R.drawable.ic_build_black_24dp);
                mBuilder.setMultiChoiceItems(afteractivitydialogitems, dialogcheckeditems, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int position, boolean isChecked) {



                        if (isChecked){
        mUserselecteditems.add(Integer.valueOf(dialogdegerleri[position]));
    }
    if (!isChecked) {
    if (mUserselecteditems.contains(Integer.valueOf(dialogdegerleri[position]))){
        mUserselecteditems.remove(Integer.valueOf(dialogdegerleri[position]));
    }
    }
     }
                });

                mBuilder.setCancelable(false);
                mBuilder.setPositiveButton("Tamamdır.", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {


                        String items = "";
                        toplamaislemi = 0;
                        for (int item : mUserselecteditems) {
                            items += "-" + item + "\n";

                            toplamaislemi = toplamaislemi + item;



   //When i want to get this value.Value is always zero(0)
                        String returnString = data.getStringExtra("selected");
                        kullanıcısayıdegerlistesi.remove(String.valueOf(returnString));
                        kullanıcısayıdegerlistesi.add(Integer.valueOf(returnString),String.valueOf(toplamaislemi));
                        oyunTextView.notifyDataSetChanged();

                    }
                }  )             .show();


            }


            super.onActivityResult(requestCode, resultCode, data);
        }

推荐答案

首先,将其放在onContextItemSelected

First of all, put this on onContextItemSelected

SharedPreferences settings = getSharedPreferences("PREFS_NAME", MODE_PRIVATE);
                SharedPreferences.Editor editor = settings.edit();
editor.clear();

                editor.putInt("kelime", selectedPosition);

                editor.commit();

在鳕鱼上方停留后,设置onActivityResult

After Settle down above cod,Set onActivityResult

SharedPreferences settings = getSharedPreferences("PREFS_NAME", MODE_PRIVATE);
                    int selec = settings.getInt("kelime",selectedPosition);

最后,将适配器设置为void:

Finally, set the adapter same void :

kullanıcısayıdegerlistesi.remove(selec);
                        kullanıcısayıdegerlistesi.add(selec ,String.valueOf(sonuc));

这篇关于活动重启时如何将意向额外信息传递给onactivityresult?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 01:05