2

When I’am inside a fragment what is the difference between this.context and this.activity Eg:

val intent = Intent(this.activity!! , Activity::class.java)

val intent = Intent(this.context!! , Activity::class.java)
daniel.jbatiz
  • 437
  • 4
  • 18
  • 2
    Does this answer your question? [What is the difference between Activity and Context?](https://stackoverflow.com/questions/6518206/what-is-the-difference-between-activity-and-context) – Mahmoud Abu Alheja Dec 25 '19 at 01:30
  • This is probably the answer you are looking for https://stackoverflow.com/questions/32227146/what-is-different-between-getcontext-and-getactivity-from-fragment-in-support-li/32227256 – gpunto Dec 25 '19 at 11:36

2 Answers2

2

with context > intent exists as long as application exists

with activity > intent exists as long as the activity exists

now you know what you need most of the cases.. :-D

Tejas
  • 433
  • 1
  • 4
  • 17
1

Context is a Superclass of Activity.

Dipankar Baghel
  • 1,932
  • 2
  • 12
  • 24