如何在alertbox关闭时获得意图? [英] How to get intent when alertbox close?

查看:87
本文介绍了如何在alertbox关闭时获得意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做的是从Listview将Intent发送到MainActivity我在alertbox中显示的listview项目



What i am doing is sending Intent to MainActivity from Listview the listview item i am displaying in alertbox

holder.txtStore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String value = holder.txtStore.getText().toString();
            Intent myIntent = new Intent(view.getContext(),MainActivity.class);
            myIntent.putExtra("restaurant_name", value);
            try {
                context.startActivity(myIntent);
            } catch (android.content.ActivityNotFoundException ex) {
                ex.printStackTrace();
                Toast.makeText(context, "yourActivity is not founded", Toast.LENGTH_SHORT).show();
            }
        }
    });





现在在MainActivity我使用按钮启动getIntent但我不想使用按钮我只想在alertbox消失时启动getIntent函数或者在MainActivity启动时启动它



这是我使用按钮调用getIntent的代码。 br $>




In MainActivity right now i am using button to start getIntent but i dont want to use button i just want to start getIntent function when alertbox disappear or ya when MainActivity start

This is my code to call getIntent using button.

mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = getIntent();
            String restaurant_name = intent.getStringExtra("restaurant_name");
            Toast.makeText(MainActivity.this, restaurant_name, Toast.LENGTH_LONG).show();
        if(restaurant_name != null ) {
            if (restaurant_name.equals("Romys")) {
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89209, 75.82759), 15.0f));
                mMap.addMarker(new MarkerOptions()
                        .position(new LatLng(26.89553, 75.82842))
                        .title("ROMYS"))
                        .showInfoWindow();


            }
        }else {
                Toast.makeText(MainActivity.this,"It was not", Toast.LENGTH_LONG).show();
            }
        }
    });





我尝试了什么:



i使用onResume onRestart但不适用于我



What I have tried:

i use onResume onRestart but not work for me

推荐答案

然后在 onCreate()函数。就像你在事件处理程序中编写代码一样,在activity的事件处理程序中编写代码; 创作

Then add the code at the onCreate() function. Just the way you have written the code in the event handler, write the code in the activity's event handler; for creation.
// Function executed when activity starts.
public void onCreate(Bundle b) { 
   Intent intent = getIntent();
   // ... Following code
}



通过这种方式,您将获得捕获的意图。基本上,要在任何地方捕获Intent对象,只需在实例上下文中执行 getIntent()函数。


这篇关于如何在alertbox关闭时获得意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆