常用Manager

  • ActivityManager:与系统中正在运行的所有活动进行交互。
    // 在拥有Context的环境下,获取:
    ActivityManager activityManager= (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    
  • PackageManager:检索当前安装在设备上的应用程序包相关的各种信息。
    PackageManager packageManager=getPackageManager();
    
  • DownloadManager:下载管理器是一个系统服务,处理长时间运行的HTTP下载。
    DownloadManager downloadManager= (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    
  • ConnectivityManager:关于网络连接状态的查询的类。
    ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    
    • 监视网络连接(Wi-Fi、GPRS、UMTS、等) 当网络连通性的变化发送广播意图
    • 当连接的网络丢失,会自动连接别的网络
    • 提供一个允许应用程序查询可用网络的粗粒度或细粒度的应用程序接口
    • 提供一个允许应用程序请求和选择网络的应用程序的接口
  • WindowManager:应用程序使用的界面和窗口管理器。
    WindowManager windowManager=getWindowManager();
    //向windowManager中添加视图
    windowManager.addView(view);
    //删除windowManager中的视图
    windowManager.removeView(view);
    
  • NotificationManager:通知用户发生的事件。
    NotificationManager notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    
  • TelephonyManager:提供访问设备上的电话服务的信息。
    TelephonyManager telephonyManager= (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    
    • getCallState():返回电话状态。
    • getCellLocation():获取当前电话的位置
    • getDataActivity():获取数据活动状态
    • getDeviceId():返回设备id
    • getLine1Number():返回手机号码
  • LocationManager:提供了系统位置服务的访问。
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    
  • AlarmManager:提供系统报警服务的访问。
    AlarmManager alarmManager= (AlarmManager) getSystemService(ALARM_SERVICE);
    
  • FragmentManager:在Activity中与Fragment进行交互的接口。

    FragmentManager fragmentManager=getSupportFragmentManager();
    
    • getFragments():获取FragmentManager中所有的Fragment。
    • findFragmentById():通过id找到对应的Fragment。
    • beginTransaction():开启FragmentManager的事务。

    FragmentManager只能直接对Fragment进行查询操作,不能直接进行增加,删除,更新操作,要进行这些操作必须在FragmentManager开启的事务中进行。开启的事务的任务都完成后要提交事务。

    fragmentManager.beginTransaction().replace(R.id.fragment,fragment).commit();
    

results matching ""

    No results matching ""