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.

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

相关文章推荐

Applied WPF 4 in Context

  • 2016-03-19 23:39
  • 4.49MB
  • 下载

什么导致了Context泄露:Handler&内部类

public class SampleActivity extends Activity { private final Handler mLeakyHandler = new Handler(...

Context-aware mobile computing

  • 2015-05-04 14:43
  • 3.13MB
  • 下载

maven 项目出现 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis...

右键菜单插件context.js

context:component-scan扫描使用上的容易忽略的use-default-filters

问题 如下方式可以成功扫描到@Controller注解的Bean,不会扫描@Service/@Repository的Bean。正确   Java代码    pack...

context文件配置

内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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