如何决定我们来自哪个活动? [英] how to decide which activity we came from?

查看:196
本文介绍了如何决定我们来自哪个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好旧运动!

要的地步,我有3个活动如下:

To the point, I have 3 activity as follows :

-activity A

-Activity A

-activity乙

-Activity B

-activityç

-Activity C

在一个活动我创建一个意图去活动C:

in activity A I create an intent to go to activity C:

Intent intent=new Intent(getActivity(),C.class);
startActivity(intent);

在活动B创建意图去活动ç太:

in activity B I create intent to go to activity C too:

Intent intent=new Intent(getActivity(),C.class);
startActivity(intent);

在活动Ç我会做不同的东西,如果从A和B的。

in activity C I am going to do something different if it's from A and B.

问题是什么是如何让活动ç知道最好实践活动A或B的是哪位?

The question is what is the best practice on 'how to let activity C know whether activity A or B that is calling ?

- 对不起缺乏英语,来自巴厘岛的问候。

-sorry lack English, greeting from bali..

推荐答案

则可以在这里做什么,你可以传递一个值说标志=A时,从活动A 标志= B 时,它是从活动B 通过意图并获得该值活动ç ...

What you can do here is, you can pass one value say flag = "A" when it is from Activity A and flag = B when it is from Activity B via Intent and get that value in Activity C ...

Intent intent = new Intent(this, C.class);
intent.putExtra("flag", "A");
startActivity(intent);

在活动B

Intent intent = new Intent(this, C.class);
intent.putExtra("flag", "B");
startActivity(intent);

在活动ç

    Intent intent = getIntent();
    String checkFlag= intent.getStringExtra("flag");

if(checkFlag.equals("A");
// It is from A

else
// It is from B

这篇关于如何决定我们来自哪个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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