如何检查哪个Intent启动了活动? [英] how to check which Intent started the activity?

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

问题描述

我有很多活动.他们每个人都有一个意图,指的是相同的活动.有没有办法找出启动该活动的意图?

I have many activities. Each one of them has an intent which refers to the same activity. Is there a way to find out which intent started the activity?

推荐答案

尝试方式:

Intent intent = new Intent();  
intent.setClass(A.this,Receiveractivity.class);
intent.putExtra("Uniqid","From_Activity_A");  
A.this.startActivity(intent);

Intent intent = new Intent();  
intent.setClass(B.this,Receiveractivity.class);
intent.putExtra("Uniqid","From_Activity_B");  
B.this.startActivity(intent);

Intent intent = new Intent();  
intent.setClass(C.this,Receiveractivity.class);
intent.putExtra("Uniqid","From_Activity_C");  
C.this.startActivity(intent);

和主要活动的onCreate中:

and in onCreate of main Activity:

//obtain  Intent Object send  from SenderActivity
 Intent intent = this.getIntent();

  /* Obtain String from Intent  */
        if(intent !=null)
        {
        String strdata = intent.getExtras().getString("Uniqid");
         if(strdata.equals("From_Activity_A"))
         {
         //Do Something here...
         }
         if(strdata.equals("From_Activity_B"))
         {
         //Do Something here...
         }
         if(strdata.equals("From_Activity_C"))
         {
         //Do Something here...
         }
         ........
        }
        else
        {
            //do something here
        }

使用 putExtra 从每个活动发送唯一键,以识别从哪个活动意图接收

use putExtra for sending Unique key from Each Activity to identify from which Activity intent is Received

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

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