@Overridepublic void onCreate(){
// TODO: It would be nice to have an option to hold a partial wakelock
// during processing, and to have a static startService(Context, Intent)
// method that would launch the service & hand off a wakelock.
super.onCreate();
HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper);
}
@Overridepublic void onStart(Intent intent, int startId){
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.obj = intent;
mServiceHandler.sendMessage(msg);
}
/**
* You should not override this method for your IntentService. Instead,
* override {@link #onHandleIntent}, which the system calls when the IntentService
* receives a start request.
*@see android.app.Service#onStartCommand
*/@Overridepublic int onStartCommand(Intent intent, int flags, int startId){
onStart(intent, startId);
return mRedelivery ? START_REDELIVER_INTENT : START_NOT_STICKY;
}
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app;
import android.annotation.WorkerThread;
import android.content.Intent;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
/**
* IntentService is a base class for {@link Service}s that handle asynchronous
* requests (expressed as {@link Intent}s) on demand. Clients send requests
* through {@link android.content.Context#startService(Intent)} calls; the
* service is started as needed, handles each Intent in turn using a worker
* thread, and stops itself when it runs out of work.
*
* <p>This "work queue processor" pattern is commonly used to offload tasks
* from an application's main thread. The IntentService class exists to
* simplify this pattern and take care of the mechanics. To use it, extend
* IntentService and implement {@link #onHandleIntent(Intent)}. IntentService
* will receive the Intents, launch a worker thread, and stop the service as
* appropriate.
*
* <p>All requests are handled on a single worker thread -- they may take as
* long as necessary (and will not block the application's main loop), but
* only one request will be processed at a time.
*
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For a detailed discussion about how to create services, read the
* <a href="{@docRoot}guide/topics/fundamentals/services.html">Services</a> developer guide.</p>
* </div>
*
*@see android.os.AsyncTask
*/
public abstract class IntentService extends Service {
private volatile Looper mServiceLooper;
private volatile ServiceHandler mServiceHandler;
private String mName;
private boolean mRedelivery;
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper){
super(looper);
}
@Overridepublic void handleMessage(Message msg){
onHandleIntent((Intent)msg.obj);
stopSelf(msg.arg1);
}
}
/**
* Creates an IntentService. Invoked by your subclass's constructor.
*
* @param name Used to name the worker thread, important only for debugging.
*/
public IntentService(String name){
super();
mName = name;
}
/**
* Sets intent redelivery preferences. Usually called from the constructor
* with your preferred semantics.
*
* <p>If enabled is true,
* {@link #onStartCommand(Intent, int, int)} will return
* {@link Service#START_REDELIVER_INTENT}, so if this process dies before
* {@link #onHandleIntent(Intent)} returns, the process will be restarted
* and the intent redelivered. If multiple Intents have been sent, only
* the most recent one is guaranteed to be redelivered.
*
* <p>If enabled is false (the default),
* {@link #onStartCommand(Intent, int, int)} will return
* {@link Service#START_NOT_STICKY}, and if the process dies, the Intent
* dies along with it.
*/
public void setIntentRedelivery(boolean enabled){
mRedelivery = enabled;
}
@Overridepublic void onCreate(){
// TODO: It would be nice to have an option to hold a partial wakelock
// during processing, and to have a static startService(Context, Intent)
// method that would launch the service & hand off a wakelock.
super.onCreate();
HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper);
}
@Overridepublic void onStart(Intent intent, int startId){
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.obj = intent;
mServiceHandler.sendMessage(msg);
}
/**
* You should not override this method for your IntentService. Instead,
* override {@link #onHandleIntent}, which the system calls when the IntentService
* receives a start request.
* @see android.app.Service#onStartCommand
*/
@Overridepublic int onStartCommand(Intent intent, int flags, int startId){
onStart(intent, startId);
return mRedelivery ? START_REDELIVER_INTENT : START_NOT_STICKY;
}
@Overridepublic void onDestroy(){
mServiceLooper.quit();
}
/**
* Unless you provide binding for your service, you don't need to implement this
* method, because the default implementation returns null.
* @see android.app.Service#onBind
*/
@Overridepublic IBinder onBind(Intent intent){
return null;
}
/**
* This method is invoked on the worker thread with a request to process.
* Only one Intent is processed at a time, but the processing happens on a
* worker thread that runs independently from other application logic.
* So, if this code takes a long time, it will hold up other requests to
* the same IntentService, but it will not hold up anything else.
* When all requests have been handled, the IntentService stops itself,
* so you should not call {@link #stopSelf}.
*
* @param intent The value passed to {@link
* android.content.Context#startService(Intent)}.
*/
@WorkerThreadprotected abstract void onHandleIntent(Intent intent);
}
IntentService is a base class for {@link Service}s that handle asynchronous
requests (expressed as {@link Intent}s) on demand. Clients send requests
through {@link android.content.Context#startService(Intent)} calls; the
service is started as needed, handles each Intent in turn using a worker
thread, and stops itself when it runs out of work.
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app;
import android.content.Intent;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
public abstract class IntentService extends Service {
private volatile Looper mServiceLooper;
private volatile ServiceHandler mServiceHandler;
private String mName;
private boolean mRedelivery;
private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper){
super(looper);
}
@Overridepublic void handleMessage(Message msg){
onHandleIntent((Intent)msg.obj);
stopSelf(msg.arg1);
}
}
public IntentService(String name){
super();
mName = name;
}
public void setIntentRedelivery(boolean enabled){
mRedelivery = enabled;
}
@Overridepublic void onCreate(){
super.onCreate();
HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper);
}
@Overridepublic void onStart(Intent intent, int startId){
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.obj = intent;
mServiceHandler.sendMessage(msg);
}
@Overridepublic int onStartCommand(Intent intent, int flags, int startId){
onStart(intent, startId);
return mRedelivery ? START_REDELIVER_INTENT : START_NOT_STICKY;
}
@Overridepublic void onDestroy(){
mServiceLooper.quit();
}
@Overridepublic IBinder onBind(Intent intent){
return null;
}
protected abstract void onHandleIntent(Intent intent);
}
Preparing:为这个类分配所需要的内存,确定这个类的属性、方法等所需的数据结构。(Prepare a data structure that assigns the memory required by classes and indicates the fields, methods, and interfaces defined in the class.)
Resolving:将该类常量池中的符号引用都改变为直接引用。(不是很理解)
Initialing:初始化类的局部变量,为静态域赋值,同时执行静态初始化块。
那么,Class Loader在加载类的时候,究竟做了些什么工作呢?
要了解这其中的细节,必须得先详细介绍一下运行数据区域。
二、运行数据区域
Runtime Data Areas:当运行一个JVM示例时,系统将分配给它一块内存区域(这块内存区域的大小可以设置的),这一内存区域由JVM自己来管理。从这一块内存中分 出一块用来存储一些运行数据,例如创建的对象,传递给方法的参数,局部变量,返回值等等。分出来的这一块就称为运行数据区域。运行数据区域可以划分为6大 块:Java栈、程序计数寄存器(PC寄存器)、本地方法栈(Native Method Stack)、Java堆、方法区域、运行常量池(Runtime Constant Pool)。运行常量池本应该属于方法区,但是由于其重要性,JVM规范将其独立出来说明。其中,前面3各区域(PC寄存器、Java栈、本地方法栈)是 每个线程独自拥有的,后三者则是整个JVM实例中的所有线程共有的。这六大块如下图所示:
Google is an American technology company that is well known for its search engine, Android operating system, Gmail mail service, GDrive cloud storage. Google started with a search engine which made it very popular and rich. In the ongoing years, Google created different technologies, services, and products. Google’s official name or the parent company is Alphabet Inc. which is established in 2015.
Google started in January 1996 as a research project by “Larry Page” and “Sergey Brin”. The domain name for the Google is registered on September 15, 1997, and the company incorporated on September 4, 1998. As an interesting event, Google was initially funded in August 1998 about $100,000 by Andy Bechtolsheim before incorporation.
Google also received money from Amazon founder Jeff Bezos, Professor David Cheriton, and entrepreneur Ram Shriram which is in total 1 million dollars. At the end of 1998 to early 1999, a new $25 million funding also received from venture capital firms.
Google’s initial public offering (IPO) took place on August 19, 2004. This made the Google total value of about $23 billion. In October 2006, Google had acquired the popular video-sharing site YouTube for $1.65 billion.
By 2011, Google was handling about 3 billion searches per day where in order to handle this request Google built 11 data centers in different locations and countries around the world. On August 15, 2011, Google made its largest acquisition to date with the “Motorola Mobility” for $12.5 billion. In 2012 Google generated $50 billion annual revenue which was $38 billion in the previous year.
On August 10, 2015, Google reorganized its interests as Alphabet and Google became Alphabet’s leading subsidiary. With this reorganization, Sundar Pichai became CEO of Google. Google became the second most valuable brand in 2013, 2014, 2015, and 2016 behind Apple with a valuation of $133 billion.
On March 19, 2019, Google announced cloud gaming platform named “Stadia”.
2019年3月19日,谷歌宣布了名为“ Stadia”的云游戏平台。
从Google Inc.到Alphabet Inc.(From Google Inc. To Alphabet Inc.)
As stated previously “Google Inc.” is named to the “Alphabet Inc.” in August 2015. Alphabet became the parent company of Google and other companies like “Calico”, “DeepMind”, “Google Fiber”, Waymo” etc. Alphabet Inc. 2019 revenue is about $161 billion most of them come from Google. The current CEO of Alphabet is Larry Page and Sergey Brin is the president.
如前所述,“ Google Inc.” 被命名为“ Alphabet Inc.” 2015年8月,Alphabet成为Google以及诸如“ Calico”,“ DeepMind”,“ Google Fiber”,Waymo”等其他公司的母公司。AlphabetInc. 2019年的收入约为1,610亿美元,其中大部分来自Google。 Alphabet的现任首席执行官是拉里·佩奇(Larry Page),塞吉·布林(Sergey Brin)是总裁。
Google服务 (Google Services)
Google is very big company which has variaty of services, products and technologies. Below we listed some of the most known and popular of them.
Google Search Engine is the first services and product of the Google. Also Google Search Engine is the one of the core business of the Google. According to the comScore Google Search is most used search engine with the 65.6% market share.
Google Search Engine是Google Search Engine的*批服务和产品。 谷歌搜索引擎也是谷歌的核心业务之一。 根据comScore,Google搜索是使用*多的搜索引擎,市场份额为65.6%。
Google Mail或Gmail(Google Mail or Gmail)
One of the other popular services is Google Mail or with its well-known name Gmail. Gmail provides email service with some auxiliary services like Calendar, Contacts, ToDo list, etc.
From the revenue point of view, Google Adsense is the most important business of Google. Google Adsense provides advertising business via the app, in-app purchases, digital content, etc.
从收入的角度来看,Google Adsense是Google*重要的业务。 Google Adsense通过应用程序,应用程序内购买,数字内容等提供广告业务。
LEARN MORE How To Manage Google Chrome Extensions? Add, Install, Update, Remove Google Chrome Browser Extension
Google developed the most popular mobile operating system Android. Android is mainly used for smartphones but also provided by different types of consumer devices like smartwatch, television, car, IoT, etc.
Google Chrome is the most popular web browser in the internet. Google Chrome supports different operating systems and platforms like Windows, Linux, Android, iOS, MacOSX etc.
Google Chrome浏览器是互联网上*受欢迎的网络浏览器。 Google Chrome支持不同的操作系统和平台,例如Windows,Linux,Android,iOS,MacOSX等。
谷歌翻译(Google Translate)
Google Translate is popular translation services that are served via https://translate.google.com/. Google Translate can translate words, sentences, or complete articles. Also “.doc”, “.docx” , “.odf”, “.pdf”, “.txt”, “.xls”, “.xlsx” documents can be uploaded and translated automatically. Google Translate supports over 100 languages around the world with the help of communities.
Google Translate是流行的翻译服务,可通过https://translate.google.com/提供。 Google翻译可以翻译单词,句子或完整的文章。 此外,“。doc”,“。docx”,“。odf”,“。pdf”,“。txt”,“。xls”,“。xlsx”文档也可以自动上传和翻译。 Google翻译在社区的帮助下支持全球100多种语言。
谷歌云(Google Cloud )
Google Cloud is an enterprise level product which is the same Amazon Web Services and Microsoft Azure. Google Cloud provide cloud services about computing, storage, database, networking, development, data analytics, AI and Machine learning, API management, security and identity, serverless computing, IoT etc.
Google Cloud是企业级产品,与Amazon Web Services和Microsoft Azure相同。 Google Cloud提供有关计算,存储,数据库,网络,开发,数据分析,AI和机器学习,API管理,安全性和身份,无服务器计算,IoT等的云服务。
Google文件和G Suite(Google Docs and G Suite)
Google Docs and G Suite provides different tools for personals and SMB’s to create, manage and share documents, corporate email address, cloud storage.
Google Docs和G Suite为个人和SMB提供了不同的工具来创建,管理和共享文档,公司电子邮件地址,云存储。