• 阿里开发手册总结


    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 的访问。

  • 相关阅读:
    mysql高级之编程优化
    高性能产品必由之路
    linux下安装xhprof
    linux下安装apc
    linux下安装vld
    python装饰器通俗易懂的解释!
    python函数基础 与文件操作
    python基础入门一(语法基础)
    iOS Keychain,SSKeychain,使用 理解 原理
    起头
  • 原文地址:https://www.cnblogs.com/spps/p/9651680.html
Copyright © 2020-2023  润新知