简体   繁体   English

开始新活动后的访问意图 android

[英]Access intent after starting new activity android

I am having an issue with something and I don't really know where to look or how to search for this, so I am asking here.我遇到了一些问题,我真的不知道在哪里寻找或如何搜索,所以我在这里问。 Basically, I am starting a new activity from my main activity using this bit of code:基本上,我正在使用这段代码从我的主要活动开始一个新活动:

Intent intent = new Intent(v.getContext(), AlarmViewer.class);
startActivity(intent);

And start my AlarmViewer class with a normal onCreate , that looks like this:并使用正常的onCreate启动我的AlarmViewer class ,如下所示:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
}

So, I am trying trying to figure out how to access the intent I used to start the activity to get some extras that I put on it.所以,我试图弄清楚如何访问我用来启动活动的意图,以获取我添加的一些额外内容。 Anyone have any idea how I can do that?有人知道我该怎么做吗? If this has been asked before I'm sorry, wasn't really sure how to search for this.如果在对不起之前有人问过这个,我真的不知道如何搜索这个。

To get the intent, use getIntent() .要获得意图,请使用getIntent()

To get your information, you use getIntent().getExtras() which returns an object of type Bundle .要获取您的信息,您可以使用getIntent().getExtras()来返回Bundle类型的 object 。 From that object, you can call the different get* methods depending on the type you have passed it from the calling activity从 object 中,您可以调用不同的get*方法,具体取决于您从调用活动中传递的类型

You can have a look at this thread for an example你可以看看这个线程的例子

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM