或者
问答详情页顶部banner图
您的位置:首页 >推广 > 其他 > 其他 > 使用uri的方式打开应用,为什么要设置Action

使用uri的方式打开应用,为什么要设置Action

提问者:小啊潘  |   分类:其他  |   浏览57次  |   悬赏分:5积分 2017-04-12 09:17:34

我要回答

提 交

匿名

  • 女***神

    看之前我们学到的代码 Intent intent = new Intent(); intent.setAction(intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.baidu.com")); startActivity(intent); 1 2 3 4 1 2 3 4 uri:用于标识某一互联网资源名称的字符串 简单理解格式如下: [scheme:][//host][path][?query][#fragment] 前面我们学习过了activity之间的跳转方法: http://blog.csdn.net/github_266****3/article/details/603****3 我们现在学习:怎么通过uri的方式,来实现(从ManActivity跳转到IndexActivity) 1、在AndroidManifest.xml 配置文件里: 1 2 3 4 5 6 7 1 2 3 4 5 6 7 2、MainActivity.Java里点击跳转代码: Intent intent = new Intent(); intent.setData(Uri.parse("diy://diy.com")); startActivity(intent); 1 2 3 1 2 3 3、为了使得程序不报错,我们需要修改以前IndexActivity.java的代码: public class IndexActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.index); //获取 Intent intent = getIntent(); //String name = intent.getExtras().get("name").toString(); String name = "首页"; //显示到控件上 ((TextView)findViewById(R.id.text1)).setText(name); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 这里写图片描述 为是要设置Action 如果我们还有一个activity,它们是scheme都是同样的。类似如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 那么在需要跳转的时候,就可以通过action名称来区分了。 Intent intent = new Intent(); intent.setAction("newslist"); intent.setData(Uri.parse("diy://diy.com")); startActivity(intent);

    2017-04-12 11:27:05
    评论0  |   0
问答详情中间banner