【第22期】观点:IT 行业加班,到底有没有价值?

Context

原创 2016年06月01日 15:19:52

Context继承于 Object, 直接子类有两个,用的多的是ContextWrapper. 而ContextWrapper的子类有Service ,ContextThemeWrapper(它的子类就是Activity)。
Context是一个抽象类,我们经常会见到它作为一个参数出现,activity(各种activity) 和service都是其子类,都可以向上转型作为一个context来使用。
它有很多方法,这摘取一些。
关于Activity的方法
1.abstract void ———- startActivity(Intent intent)
Same as startActivity(Intent, Bundle) with no options specified.
2.abstract void ———- startActivity(Intent intent, Bundle options)
Launch a new activity.
3.abstract void ———- startActivities(Intent[] intents, Bundle options)
Launch multiple new activities.
4.abstract void ———- startActivities(Intent[] intents)
Same as startActivities(Intent[], Bundle) with no options specified.

关于服务的一些方法
1.abstract boolean ———- bindService(Intent service, ServiceConnection conn, int flags)
Connect to an application service, creating it if needed.
2.abstract ComponentName ———- startService(Intent service)
Request that a given application service be started.
3.abstract boolean ———- stopService(Intent service)
Request that a given application service be stopped.
4.abstract void ———- unbindService(ServiceConnection conn)
Disconnect from an application service.
关于广播的一些方法
注册广播:
1.abstract Intent ———- registerReceiver(BroadcastReceiver receiver, IntentFilter filter)
Register a BroadcastReceiver to be run in the main activity thread.
2.abstract Intent ———- registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler)
Register to receive intent broadcasts, to run in the context of scheduler.
发送广播:
3.abstract void ———-sendBroadcast(Intent intent)
Broadcast the given intent to all interested BroadcastReceivers.
4.abstract void ———- sendBroadcastAsUser(Intent intent, UserHandle user)
Version of sendBroadcast(Intent) that allows you to specify the user the broadcast will be sent to.
5.abstract void———- sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission)
Version of sendBroadcast(Intent, String) that allows you to specify the user the broadcast will be sent to.
6.abstract void ———- sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)
Version of sendBroadcast(Intent) that allows you to receive data back from the broadcast.
7.abstract void ———- sendOrderedBroadcast(Intent intent, String receiverPermission)
Broadcast the given intent to all interested BroadcastReceivers, delivering them one at a time to allow more preferred receivers to consume the broadcast before it is delivered to less preferred receivers.
注销广播:
8.abstract void ———- unregisterReceiver(BroadcastReceiver receiver)
Unregister a previously registered BroadcastReceiver.
得到系统服务
abstract Object ———- getSystemService(String name)
Return the handle to a system-level service by name.
得到包名
abstract String ———- getPackageName()
Return the name of this application’s package.
得到包资源路径
abstract String ———- getPackageResourcePath()
Return the full ath to this context’s primary Android package.
得到资源
abstract Resources ———- getResources()
Return a Resources instance for your application’s package.
得到SharedPreferences
abstract SharedPreferences ———- getSharedPreferences(String name, int mode)
Retrieve and hold the contents of the preferences file ‘name’, returning a SharedPreferences through which you can retrieve and modify its values.

版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

spring学习 一 <context:component-scan>使用说明

在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的Java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些...

spring组件<context:component-scan>

在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类注册为bean 注意:如果配置了&lt;context:component-scan&am...
  • lopez
  • lopez
  • 2016-01-29 14:39
  • 57

程序员升职加薪指南!还缺一个“证”!

CSDN出品,立即查看!

弱智问题导致context.xml解析错误,特记录

前阵子,准备重新测试一下tomcat对context.xml中数据源的处理情况,当时我的context.xml是这样写的,并且放在web目录下的META-INF目录下 1...

spring context 扫描与 mvc扫描类 区分开包

1.applicationContext.xml 2.springmvc-servlet.xml

stream_context_create()模拟POST/GET

在 PHP 程序里,给你一个数组,如何将这个数组 POST/GET 到另外一个地址呢?当然,使用 CURL 很容易办到,那么如果不使用 CURL 库,又该怎么办呢?其实,在 PHP 里已经有相关的...
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)