简体   繁体   English

在getApplicationContext()或Activity之间使用上下文创建Intent有何区别?

[英]What's the difference for creating an Intent with context between getApplicationContext() or activity

We always create an Intent with context 我们总是根据上下文创建一个Intent

Intent intent = Intent(context, SomeClass.class)

I can use this(activity) or getActivity(fragment) as context, in some situations I can use getApplicationContext. 我可以使用this(activity)或getActivity(fragment)作为上下文,在某些情况下,我可以使用getApplicationContext。

My question is what't the difference for Intent under there two circumstances? 我的问题是,在两种情况下Intent有什么区别?

getApplicationContext()提供应用程序上下文,但是上下文提供当前活动上下文。希望它对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android中的活动和意图有什么区别? - What's the difference between activity and intent in Android? 实例化对象和调用getApplicationContext()有什么区别? - What's the difference between instantiating an object and calling getApplicationContext()? Activity 和 Context 有什么区别? - What is the difference between Activity and Context? ContextCompat.startForegroundService(context,intent)和startforegroundservice(intent)之间有什么区别? - What is the difference between ContextCompat.startForegroundService(context, intent) and startforegroundservice(intent)? 在活动与接收者中声明意图过滤器有什么区别? - What's the difference between declaring an intent-filter in an activity vs. a receiver? Toast:“this”和“getApplicationContext()”之间的区别? - Toast: Difference between “this” and “getApplicationContext()”? getApplicationContext()和getActivity()之间的区别 - Difference between getApplicationContext() and getActivity() 活动中的意图过滤器和广播接收器有什么区别? - What is the difference between intent filter in activity and broadcast receiver? 在Toast .maketext()方法中使用getApplicationcontext()和this之间的区别是什么 - What is the Difference between using getApplicationcontext() & this in Toast .maketext() method this 和 Activity.this 有什么区别 - What's the difference between this and Activity.this
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM