`
敲敲大葱头
  • 浏览: 29844 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

this.getApplicationContext()☆☆☆

UP 
阅读更多
public class
ContextWrapper

abstract Context getApplicationContext()
Return the context of the single, global Application object of the current process.

API :
Return the context of the single, global Application object of the current process. This generally should only be used if you need a Context whose lifecycle is separate from the current context, that is tied to the lifetime of the process rather than the current component.
Consider for example how this interacts with registerReceiver(BroadcastReceiver, IntentFilter):
If used from an Activity context, the receiver is being registered within that activity. This means that you are expected to unregister before the activity is done being destroyed; in fact if you do not do so, the framework will clean up your leaked registration as it removes the activity and log an error. Thus, if you use the Activity context to register a receiver that is static (global to the process, not associated with an Activity instance) then that registration will be removed on you at whatever point the activity you used is destroyed.
If used from the Context returned here, the receiver is being registered with the global state associated with your application. Thus it will never be unregistered for you. This is necessary if the receiver is associated with static data, not a particular component. However using the ApplicationContext elsewhere can easily lead to serious leaks if you forget to unregister, unbind, etc.
分享到:
评论

相关推荐

    Android Context与GetApplicationContext的区别及使用1

    当你在Activity中使用`this`或`XXXActivity.this`时,你实际上获取的是Activity的Context,它包含了当前Activity的状态和生命周期。而`getApplicationContext()`返回的是Application的Context,这是一个全局的、与...

    Spring获取ApplicationContext对象工具类的实现方法

    然后,通过getApplicationContext方法,可以返回这个已经加载好的ApplicationContext实例。 使用这个工具类非常简单。例如,如果你需要获取一个名为"userService"的Bean实例,可以这样做: ```java public static ...

    生活轨迹Android端

    Toast.makeText(YLC_APPLICATION.getInstance().getApplicationContext(), "您的网络出错啦!", Toast.LENGTH_LONG).show(); }else if (isError == MKEvent.ERROR_NETWORK_DATA) { Toast.makeText(YLC_...

    CameraWindow.java

    支持在Android的环境下,通过摄像头进行用户无感知的拍照 使用者自己新建Android工程,然后倒入...然后在工程的需要拍照的逻辑中调用CameraWindow.showWindow(this.getApplicationContext(), 0);即可实现无感知拍照。

    AssetsCopier:因为我们在开发android应用程序时无法在C ++(JNI)代码中使用文件的绝对路径。 因此,我们将资产文件复制到SdCard

    我们可以使用AssetsCopier的静态函数: 公共静态无效copyAllAssets(上下文上下文,字符串目标) 基本用法如下: AssetsCopier.copyAllAssets(this.getApplicationContext(),this.getExternalFilesDir(null)....

    表格的增删改查

    Toast.makeText(act.getApplicationContext(), "添加成功", Toast.LENGTH_LONG).show(); } break; case R.id.btn_check: User user_check = new User(null, null); UserDao userDao_check =...

    三步搞定:Vue.js调⽤Android原⽣操作

    mAgentWeb.getJsInterfaceHolder().addJavaObject("android",new AndroidInterfaceForJS(mAgentWeb,this.getApplicationContext())); AgentWebSettings agentWebSettings = mAgentWeb.getAgentWebSettings(); ...

    WifiLocLib:您可以在 5 分钟内使用的 Wi-Fi 定位器

    Toast t = Toast.makeText(this.getApplicationContext(), "Location: " + location,Toast.LENGTH_SHORT); t.setGravity(Gravity.CENTER, 0, 0); t.show(); Log.d("LOCATION", "LOCATION: " + location); }

    安卓总结的文档

    安卓基本语句有public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here.... myIntent=new Intent(getApplicationContext(), FrmMain.class); } //2监听器

    libstreaming-master.zip

    .setContext(getApplicationContext()) .setVideoEncoder(SessionBuilder.VIDEO_H264) .setVideoQuality(new VideoQuality(1280, 720)); this.startService(new Intent(this,RtspServer.class));

    详解spring boot容器加载完后执行特定操作

    OSSVideoRepository ossVideoRepository = (OSSVideoRepository) event.getApplicationContext().getBean(OSSVideoRepository.class); // 在容器加载完毕后获取配置文件中的配置 ServerConfig serverConfig = ...

    Android 判断网络是否可用 & 获取IP地址 & 获取以太网口MAC地址

    判断网络是否可用: 注意!是判断网络是否可用,但网络可用不代表一定能上外网的! public static boolean ... .getApplicationContext().getSystemService( Context.CONNECTIVITY_SERVICE); if (m

    Html离线缓存webview配置详细

    String databasePath = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); webseting.setDatabasePath(databasePath); ``` 7. **启用JavaScript** 许多网页依赖于JavaScript...

    百度地图 定位城市或者详细信息

    mLocationClient = new LocationClient(context.getApplicationContext()); //声明LocationClient类 LocationClientOption option = new LocationClientOption(); option.setLocationMode(LocationMode.Hight_...

    Android 文件读写源码

    Button button = (Button) this.findViewById(R.id.button); button.setOnClickListener(new ButtonClickListener()); } private final class ButtonClickListener implements View.OnClickListener{ ...

    Android输入手机号发送短信示例.rar

      PendingIntent sendPI = PendingIntent.getBroadcast(getApplicationContext(), 0, intentSend, 0);   smsManager.sendTextMessage(strNumber, null, strBody, sendPI, null);//发送短信   send.setEnabled...

    spring注解Quartz定时执行功能

    this.executeTask(); } } ``` 在上面的例子中,`executeTask`方法是定时任务的执行体,`cron = "0/5 * * * * ?"`定义了任务的执行周期,即每5秒执行一次。`execute`方法是Quartz Job接口要求的方法,我们将其调用...

    SelfInstall-Jelly-Bean:应用程序的自安装程序

    PackageManager manager = mycon.getApplicationContext().getPackageManager();intent = manager.getLaunchIntentForPackage(selfInstallerPackageName);intent.addCategory(Intent.CATEGORY_LAUNCHER);intent....

    permissions.jar

    PermissionHelper.requestPermission(this, new RequestPermissionListener() { @Override public void onSuccess() { Toast.makeText(getApplicationContext(),"权限成功获取",Toast.LENGTH_SHORT).show(); } ...

    android 6.0下webview的定位权限设置方法

    如下所示: WebView webView = (WebView)findViewById(R.id.webview); WebSettings webSettings = webView.getSettings();...String dir = this.getApplicationContext().getDir(database, Context.MODE

Global site tag (gtag.js) - Google Analytics