Submit Search
Upload
第八堂 學習使用 Service
•
Download as PPTX, PDF
•
2 likes
•
523 views
力中 柯
Follow
Jason 的 Android 應用程式快樂學習班 --- 第八堂 學習使用 Service
Read less
Read more
Software
Report
Share
Report
Share
1 of 23
Download now
Recommended
第四堂 Android 的架構與開發工具
第四堂 Android 的架構與開發工具
力中 柯
第九堂 手機的資料保存
第九堂 手機的資料保存
力中 柯
第五堂 計算機App與網站瀏覽app
第五堂 計算機App與網站瀏覽app
力中 柯
第十堂 Android 5.0 lollipop
第十堂 Android 5.0 lollipop
力中 柯
第一堂 進入 Android 的世界 --- Jason 的 Android 應用程式快樂學習班
第一堂 進入 Android 的世界 --- Jason 的 Android 應用程式快樂學習班
力中 柯
第七堂 Youtube 播放 app (2)
第七堂 Youtube 播放 app (2)
力中 柯
第六堂 Youtube 播放 App (1)
第六堂 Youtube 播放 App (1)
力中 柯
第十一堂 學習編譯與上架
第十一堂 學習編譯與上架
力中 柯
Recommended
第四堂 Android 的架構與開發工具
第四堂 Android 的架構與開發工具
力中 柯
第九堂 手機的資料保存
第九堂 手機的資料保存
力中 柯
第五堂 計算機App與網站瀏覽app
第五堂 計算機App與網站瀏覽app
力中 柯
第十堂 Android 5.0 lollipop
第十堂 Android 5.0 lollipop
力中 柯
第一堂 進入 Android 的世界 --- Jason 的 Android 應用程式快樂學習班
第一堂 進入 Android 的世界 --- Jason 的 Android 應用程式快樂學習班
力中 柯
第七堂 Youtube 播放 app (2)
第七堂 Youtube 播放 app (2)
力中 柯
第六堂 Youtube 播放 App (1)
第六堂 Youtube 播放 App (1)
力中 柯
第十一堂 學習編譯與上架
第十一堂 學習編譯與上架
力中 柯
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
More Related Content
Featured
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Featured
(20)
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
第八堂 學習使用 Service
1.
第八堂: 學習使用 Service 柯力中 Jason
Ko Jason的Android 快樂應用程式學習班
2.
課程內容 • Service 服務 •
Thread 和 Handler • Toast • AlertDialog • Notification • 利用 Service 組合做出 Timer 計時器 Jason的Android 快樂應用程式學習班
3.
Service 服務 Jason的Android 快樂應用程式學習班
4.
Service 服務 • Service
是 Android 的主要建構單元之一, 和 Activity 不同, Service 不會有使用者介面, 是背景執行一段程 式碼 • Service 在背景執行, 不受 Activity 影響 • Service 可分為 bound service 跟 unbound service 兩 種 • unbound service 只有開始跟停止兩個狀態 Jason的Android 快樂應用程式學習班
5.
Service 的 Lifecycle Jason的Android
快樂應用程式學習班
6.
IntentService Jason的Android 快樂應用程式學習班 • IntentService
是另外開一條 Thread • IntentService 同一時間只能有一個在跑 • 因為 IntentService 不在 main thread 上, 可以 用來下載網路資料
7.
ex. 利用 Service
每隔一秒輸出文字 Jason的Android 快樂應用程式學習班 1. 建立一個 Project, 名稱為 ServiceTimer 2. 在 MainActivity 做一個開始 button 與一個停止 button 3. 新建一個 TimerService extends IntentService 4. 當按下開始 button 時, 每隔一秒在 Log 輸出文字”still running”, 當 按下停止 button 時, 停止輸出文字 開始 停止 Log still running… still running… still running…
8.
Thread 與 Handler Jason的Android
快樂應用程式學習班
9.
Thread 與 Handler Jason的Android
快樂應用程式學習班 MainThread Thread 報告, 處理好了, 需要更新 UI Handler 交給我就好, 我來處理
10.
ex. 改變按鈕狀態 Jason的Android 快樂應用程式學習班 1.
將兩個 button 變成一個 button 2. 當 service 在跑時, button 文字為停止 3. 當輸出十個 “still running” 後, 停止 Service, 並變更 button 文字為 開始 停止 Log still running… still running… still running…
11.
Toast Jason的Android 快樂應用程式學習班
12.
Toast Jason的Android 快樂應用程式學習班 • 短暫浮出的訊息框,
用意是提醒使用者, 不需做任何動 作
13.
ex. 倒數結束時, 顯示
Toast 訊息 Jason的Android 快樂應用程式學習班 1. 當跑完 10 秒後, Toast 顯示 “倒數結束!” 開始 倒數結束!
14.
AlertDialog Jason的Android 快樂應用程式學習班
15.
AlertDialog Jason的Android 快樂應用程式學習班 still running… •
AlertDialog 是一個彈出的視窗 (對話框), 用意是讓 使用者決定接下來的動作 setTitle() setView() setPositiveButton(), setNegativeButton()
16.
ex. 建立一個 TextView,
點及時彈出設置秒 數的 AlertDialog Jason的Android 快樂應用程式學習班 1. 建立一個 AlertDialog 需要的 layout, 取名為 custom_dialog 2. 在 MainActivity 中 new AlertDialog.Builder() 3. 利用 LayoutInflater 取得 custom_dialog 4. setTitle(), setView(), setPositiveButton(), setNegativeButton()
17.
Notification Jason的Android 快樂應用程式學習班
18.
Notification Jason的Android 快樂應用程式學習班 • 顯示在使用者訊息面板的訊息框
19.
Notification setSmallIcon() setContentTitle() setContentText()
20.
ex. 當按下開始的時候, 彈出 Notification,
倒數結束的時候, 結束 Notification 1. 按下開始 Button 時, 產生 Notification 2. 在 TimerService 內, startForeground() 3. 倒數結束時, stopForeground() P.S stopForeground() 表示移除 service 的 foreground state, allowing it to be killed if more memory is needed.
21.
利用 Service 組合做出
Timer Jason的Android 快樂應用程式學習班
22.
利用 Service 組合做出
Timer • 想像 Timer 的狀態 • 取得系統的時間 • 開始計時時, 彈出 Notification • 比較經過了多少時間 • 不斷更新 TextView • 時間結束時, 彈出 Toast Jason的Android 快樂應用程式學習班 Calendar c = Calendar.getInstance(); int currentSeconds = (int) (c.getTimeInMillis()/1000);
23.
完整程式碼 Jason的Android 快樂應用程式學習班 https://github.com/KosbrotherSchool/Teach_Timer Service
Download now