<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Mobile_Apps_2023W_Lecture_7</id>
	<title>Mobile Apps 2023W Lecture 7 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Mobile_Apps_2023W_Lecture_7"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Mobile_Apps_2023W_Lecture_7&amp;action=history"/>
	<updated>2026-05-12T22:12:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Mobile_Apps_2023W_Lecture_7&amp;diff=24334&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Notes==  &lt;pre&gt; Lecture 7 ---------  For next time: doing HTTP requests &amp; getting responses, working with REST APIs in Android and Kotlin  Today: Processes &amp; Threads in Android  A process is a running program on UNIX/Linux (and Windows)  - has its own share of memory and CPU resources  - isolated from the rest of the system (cannot see the memory of other processes)  The CPU runs a process for a while then switches to running other processes   - the OS scheduler in the...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Mobile_Apps_2023W_Lecture_7&amp;diff=24334&amp;oldid=prev"/>
		<updated>2023-02-02T03:21:44Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Notes==  &amp;lt;pre&amp;gt; Lecture 7 ---------  For next time: doing HTTP requests &amp;amp; getting responses, working with REST APIs in Android and Kotlin  Today: Processes &amp;amp; Threads in Android  A process is a running program on UNIX/Linux (and Windows)  - has its own share of memory and CPU resources  - isolated from the rest of the system (cannot see the memory of other processes)  The CPU runs a process for a while then switches to running other processes   - the OS scheduler in the...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 7&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
For next time: doing HTTP requests &amp;amp; getting responses, working with REST APIs in Android and Kotlin&lt;br /&gt;
&lt;br /&gt;
Today: Processes &amp;amp; Threads in Android&lt;br /&gt;
&lt;br /&gt;
A process is a running program on UNIX/Linux (and Windows)&lt;br /&gt;
 - has its own share of memory and CPU resources&lt;br /&gt;
 - isolated from the rest of the system (cannot see the memory of other processes)&lt;br /&gt;
&lt;br /&gt;
The CPU runs a process for a while then switches to running other processes&lt;br /&gt;
  - the OS scheduler in the kernel chooses which process to run next&lt;br /&gt;
  - a process can make a request that causes it to be paused (a system call)&lt;br /&gt;
  - or a process runs for too long and a timer goes off and it is interrupted&lt;br /&gt;
&lt;br /&gt;
A thread is part of a process, it is a CPU context&lt;br /&gt;
 - basically, the state associated with running the program&lt;br /&gt;
 - we can have just one thread, which is what we have with a standard sequential program&lt;br /&gt;
 - or we can have a multi-threaded process, with multiple CPU contexts&lt;br /&gt;
   (so logically it is doing more than one thing at the same time)&lt;br /&gt;
&lt;br /&gt;
So an app is running in at least one process, but an app can have multiple processes&lt;br /&gt;
 - and apps can even share processes in some situations (but they have to all&lt;br /&gt;
   be created by the same developer)&lt;br /&gt;
&lt;br /&gt;
In Android, there is the concept of a &amp;quot;UI thread&amp;quot;&lt;br /&gt;
 - so in the main app&amp;#039;s process, the UI thread is the one interacting with the user, controlling the visible activities&lt;br /&gt;
 - you can have other threads, but they will be worker threads and may not manipulate the interface&lt;br /&gt;
    - they must send requests to the UI thread, it will then update the screen&lt;br /&gt;
&lt;br /&gt;
If you do time-intensive operations in the UI thread, the UI thread will block and so the interface will freeze until the operations finish&lt;br /&gt;
&lt;br /&gt;
So why not always put things in threads, why would we use separate processes for an activity, app, or background service?&lt;br /&gt;
  - threads share all memory&lt;br /&gt;
  - so if you&amp;#039;re doing something dangerous or unsafe, or something that just should be separate, you want to do it in a separate process&lt;br /&gt;
     - processing user input is in general unsafe, so often good to segregate it&lt;br /&gt;
&lt;br /&gt;
Modern web browsers are multi-process precisely because of this&lt;br /&gt;
 - web page content isn&amp;#039;t trusted, could be malicious, so is put into a separate process to keep it from messing with info in other tabs/windows&lt;br /&gt;
&lt;br /&gt;
See https://developer.android.com/guide/components/processes-and-threads&lt;br /&gt;
for background&lt;br /&gt;
&lt;br /&gt;
Multithreaded programming in C is a real pain&lt;br /&gt;
but it isn&amp;#039;t so bad in Kotlin/Java, things stay separate in a nice way for the most part&lt;br /&gt;
&lt;br /&gt;
We really need to make our app concurrent so it can deal with a user, the network, storage (files, databases) and processing data all at the same while keeping the interface responsive&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>