-1

I was trying to understand the threading in android. As we know, we can't update a view from background thread. I was trying to understand with different cases and came across a case below. When I clicked on the Start work button, I created a thread and after 5 sec I changed the textview value from that thread. Why is it working fine and app not crashing as I am updating a view from another thread not UI thread? Can anyone explain it?

Here's image of code Here's image of code -----------------------------ds

RF1991
  • 2,037
  • 4
  • 8
  • 17
  • 1
    Providing CODE instead of images of it helps to get much faster recommendations from the community.it is one of the reasons that you get Downvote – eng Aug 12 '23 at 12:25
  • Please provide enough code so others can better understand or reproduce the problem. – Community Aug 14 '23 at 11:23

1 Answers1

0

The app works because you are updating it from the same context (same memory space). If you had a service which would directly interact "somehow" with your visible app content, for example by passing the app context to the service, then it would crash. For example, you can't use a Toast message from within a service, because the context of the service, even by using getApplicationContext(), represents the operating system and not your app. You may however use a notification, because notifications are reachable from the OS.