zoukankan      html  css  js  c++  java
  • 阿里开发手册总结

    Activity 间通过隐式Intent 的跳转,在发出Intent 之前必须通过resolveActivity
    检查,避免找不到合适的调用组件,造成ActivityNotFoundException 的异常。
    正例:
    public void viewUrl(String url, String mimeType) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse(url), mimeType);
    if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_
    ONLY) != null) {
    startActivity(intent);
    }else {
    // 找不到指定的Activity
    }
    }
    反例:
    Intent intent = new Intent();
    intent.setAction("com.example.DemoIntent ");
    try {
    startActivity(
    } catch (ActivityNotFoundException e) {
    e.printStackTrace();
    }

    Intent.ACTION_VIEW 说明

    String android.intent.action.VIEW

    用于显示用户的数据。比较通用,会根据用户的数据类型打开相应的Activity。比如 tel:13400010001打开拨号程序,http://www.g.cn则会打开浏览器等。

    代码1:

    Uri uri = Uri.parse("http://www.google.com"); //浏览器(网址必须带http)
    //Uri uri =Uri.parse("tel:1232333"); //拨号程序
    //Uri uri=Uri.parse("geo:39.899533,116.036476"); //打开地图定位

    Intent it = new Intent(Intent.ACTION_VIEW,uri); //Intent.ACTION_VIEW不带引号


    如果广播仅限于应用内,则可以使用LocalBroadcastManager#sendBroadcast()实
    现,避免敏感信息外泄和Intent 拦截的风险。
    正例:
    Intent intent = new Intent("my-sensitive-event");
    intent.putExtra("event", "this is a test event");
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);


    灵活使用布局,推荐merge、ViewStub 来优化布局,尽可能多的减少UI
    布局层级,推荐使用FrameLayout,LinearLayout、RelativeLayout 次之。

    】当使用外部存储时,必须检查外部存储的可用性

    WebView 应设置 WebView#getSettings()#setAllowFileAccess(false)、
    WebView#getSettings()#setAllowFileAccessFromFileURLs(false) 、
    WebView#getSettings()#setAllowUniversalAccessFromFileURLs(false),阻止 file
    scheme URL 的访问。

  • 相关阅读:
    bzoj4753: [Jsoi2016]最佳团体(分数规划+树形依赖背包)
    bzoj2956: 模积和(数论)
    51nod 1766 树上的最远点对(线段树)
    bzoj2621: [Usaco2012 Mar]Cows in a Skyscraper(状压DP)
    Codeforces Round #441 Div. 2题解
    bzoj4569: [Scoi2016]萌萌哒(ST表+并查集)
    iOS和Android后台机制对比
    UIApplicationDelegate 各方法回调时机
    iOS OC和JS的交互 javaScriptCore方法封装
    iOS应用的执行原理
  • 原文地址:https://www.cnblogs.com/spps/p/9651680.html
Copyright © 2011-2022 走看看