{"id":1387,"date":"2010-11-14T01:51:33","date_gmt":"2010-11-13T20:51:33","guid":{"rendered":"http:\/\/aasims.wordpress.com\/?p=1387"},"modified":"2025-04-29T11:56:28","modified_gmt":"2025-04-29T11:56:28","slug":"kindle-tutorial-3","status":"publish","type":"post","link":"https:\/\/aasimnaseem.com\/blog\/kindle-tutorial-3\/","title":{"rendered":"Amazon Kindle Application Development Tutorial \u2013 Part 3"},"content":{"rendered":"<h1 style=\"text-align: center;\">Kindle Application Lifecycle<\/h1>\n<p>Hello, everyone.<br \/>\nHope you are fine and doing well in your daily routine.<\/p>\n<p>Here is the 3<sup>rd<\/sup> part of my series of tutorials on <a href=\"https:\/\/aasimnaseem.com\/index.php\/category\/my-tutorials\/amazon-kindle\/\">Amazon Kindle Application Development<\/a>.<\/p>\n<p>Note : So far we have discussed the following topics in this category.<\/p>\n<ul>\n<li><a href=\"https:\/\/aasimnaseem.com\/index.php\/2010\/09\/16\/amazon-kindle\/\">Amazon Kindle :: An Introduction<\/a><\/li>\n<li><a href=\"https:\/\/aasimnaseem.com\/index.php\/2010\/10\/22\/kindle-tutorial-1\/\">Amazon Kindle Tutorial\u00a0\u2013\u00a0Part 1 :: Basic Concepts<\/a><\/li>\n<li><a href=\"https:\/\/aasimnaseem.com\/index.php\/2010\/10\/31\/kindle-tutorial-2\/\">Amazon Kindle Tutorial\u00a0\u2013\u00a0Part 2 ::\u00a0Setting up Your System For Amazon Kindle<\/a><\/li>\n<li><a href=\"https:\/\/aasimnaseem.com\/index.php\/2010\/11\/14\/kindle-tutorial-3\/\">Amazon Kindle Tutorial\u00a0\u2013\u00a0Part 3 ::\u00a0Kindle Application Lifecycle<\/a><\/li>\n<\/ul>\n<p>In this part I will describe some core concepts that one must know before starting development on the Kindle platform. It includes the life cycle of the Kindle application and some other key points we have to care about during code.<\/p>\n<p>Earlier i was going to start the Hello World tutorial, but I felt these things should be discussed first so that when one starts writing his\/her first program, he\/she should be clear about what&#8217;s going on at the backend. So let start.<\/p>\n<p>I have brought my bowl of \u201cfruit salad,\u201d but my music player is silent today. I\u2019m not in the mood to listen to any track, but while reading these lines, don\u2019t forget to follow the traditions. You must have something to eat and listen, having relax seat in your chair \u2026<\/p>\n<p>Alright, here we go&#8230;<\/p>\n<h2><strong>Active Content<\/strong><\/h2>\n<p>First of all, we need to know what &#8220;active content&#8221; is. Within the community of Kindle developers, you will hear this term time and again. Active content is nothing but the apps that runs over <a href=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2010\/09\/16\/amazon-kindle\/\">kindle device<\/a>. Simply the apps for Kindle, here we call them &#8220;active conten\u201dt. Simple it is.<\/p>\n<h2><strong>Kindlet<\/strong><\/h2>\n<p>Technically, kindlet is an interface in kdk (kindle development kit). We extends its subclass and write our code. At little abstract level, the main entrance of our kindle application is called kindlet.<\/p>\n<p>For example like any java program must have a class that contains main() method; to start application from that point (.i.e.\u00a0 via main() method) same in case of kindle app, there must be a class that must extend subclass of kindlet interface (<em>AbstractKindlet class) <\/em>and hence become entry point of our kindle app. Such class is normally refer as kindlet of our kindle app.<\/p>\n<p>In more concise words, if someone asks you where is your kindlet, then it means he\/she is asking about the entry point of your kindle application, the class which extends the subclass of kindlet interface of kdk .i.e \u00a0<em>AbstractKindlet class.<\/em><\/p>\n<h2>Lifecycle of Kindle application<\/h2>\n<p>Like every application, active contents have also a defined life cycle. Our application move in between these life cycle phases during its execution and terminates from its exit point.\u00a0 There are four phases application move among. They are<\/p>\n<ul>\n<li><strong>loaded<\/strong><\/li>\n<li><strong>ready to run<\/strong><\/li>\n<li><strong>running<\/strong><\/li>\n<li><strong>shutdown<\/strong><\/li>\n<\/ul>\n<p>when application jumps into a phase, a specific method is called, defined in kindlet interface. These method calls and phase changes are very well defined until any unchecked exception is thrown, that causes the active content to die\/shut down and user will see crash. Now as application crashed, there isn\u2019t no surety whether the life cycle will complete normally or will terminate immediately.<\/p>\n<p>The kindlet method associates with above mentioned phases are<\/p>\n<ul>\n<li><strong>create()<\/strong><\/li>\n<li><strong>start()<\/strong><\/li>\n<li><strong>stop()<\/strong><\/li>\n<li><strong>destroy()<\/strong><\/li>\n<\/ul>\n<p>Refer the following image describing the phases and method calls during the life cycle of kindle application<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><em>{src : kdk documentation}<\/em><\/p>\n<p>Lets discuss different phases of life cycle<\/p>\n<h3><strong>Loaded<\/strong><\/h3>\n<p>When we chose a kindle application to run, its kindlet initialized, along with other static initialization of application. Once this happened, its means kindlet object has been constructed and properly initialized, hence application has LOADED.<\/p>\n<p>At this stage, we don\u2019t see any screen\/user interface at user end. Its all occurred at backend. At developer lever, we don\u2019t have access to persistent storage; we haven\u2019t access to application environment\/context.<\/p>\n<ul>\n<li>After loaded phase, there are two possible ways. Either application will enter in \u201cready to run\u201d phase or will \u201cshutdown\u201d. In case of shutdown kindlet will not notified.<\/li>\n<\/ul>\n<h3><strong>Ready to run<\/strong><\/h3>\n<p>In case application are eligible for \u201cready to run\u201d then a transition is occur via method called create() declaired in Kindlet interface. At this stage application gain access to kindle environment and we have a reference of KindletContext object. This object represents the Kindle application&#8217;s environment for a\u00a0Kindlet and provides access to the Kindlet&#8217;s user interface, filesystem space, network connectivity and more.<\/p>\n<p>Once a Kindlet\u00a0<code>create<\/code> method has finished, the Kindlet is considered &#8220;ready to run&#8221;. The application&#8217;s user interface is not visible while in the &#8220;ready to run&#8221; state and no user input will be received.\u00a0<em>be patient<\/em><\/p>\n<p>The next phase from &#8220;ready to run&#8221; is to &#8220;running&#8221;. During this <code>start()<\/code> method of kindlet interface will be called. Even at this point, the user interface is still not visible.<\/p>\n<p>&#8220;ready to run&#8221; to &#8220;shutdown&#8221; is also possible. If this occurs,\u00a0<code>destroy<\/code> will be called. During\u00a0<code>destroy<\/code>, the application should release any resources it has allocated.<\/p>\n<h3>Running Phase<\/h3>\n<p>The end of start() method moves the application in running state. At this point user interface become visible and application is said to be running state. User \u00a0can start using application.<\/p>\n<ul>\n<li>Note: one thing \u00a0need to know. When user plug usb cable to device,\u00a0 then \u00a0the device goes to screen saver and its stop() method calls for current running application. You can&#8217;t use device when its plug with usb cable. The\u00a0<code>stop()<\/code> method should pause any executing work, release any file or network resources, and prepare for the user interface to be made invisible. At this stage application move to \u201cready to run\u201d state again.<\/li>\n<\/ul>\n<h3><strong>Shutdown State<\/strong><\/h3>\n<p>When use wants to quit the application, the application moves to shutdown state and stop () method is called. This pause any executing work, release any file or network resources, and prepare for the user interface to be made invisible.<\/p>\n<p>That\u2019s was a theoretical concepts for life cycle of a kindle application. Let have a quick glance over life cycle methods of kindlet.<\/p>\n<h3>create<\/h3>\n<p>is the first step in the life cycle. A reference to the application&#8217;s environment is provided to this method. This method will only be called once during the life of the Kindlet instance.<\/p>\n<h3>start<\/h3>\n<p>indicates that the application is about to become active. Upon completion of the start method, the user interface will become visible and the application will start to receive events from the user. Unlike\u00a0create,\u00a0start\u00a0may be called many times during the overall life of the Kindlet instance. For instance, entering and exiting the screensaver results in a stop event followed by a start event. Similar cases exist for USB and other system notifications.<\/p>\n<h3>stop<\/h3>\n<p>indicates that the application should stop. The user interface will become invisible shortly after this method completes. When the user interface becomes invisible any open option panes will be closed. Stop will be called on a running application when the Kindle enters USB mode, screensaver or exits the application.<\/p>\n<p>When an application is stopped, the file system may disappear. It is important for applications to close resources like files and re-open them on stop \/ start cycles, respectively. Additionally, any threads that are performing work should either shutdown or sleep. This includes network access, and all requests for connectivity may be cancelled on stop.<\/p>\n<h3>destroy<\/h3>\n<p>indicates that the Kindlet instance will not be used again. This permits the Kindlet to clean up resources and do any housekeeping that may be necessary on application exit.<\/p>\n<p>The device may choose to shutdown an application during screen saver or USB mode to preserve battery life.<\/p>\n<p>Its enough for today .. in next part, we will move to actual development, a hello world program. though i start working that part today but i felt we should discuss these things first so that while writing the code, we should know what actually going inside code and at backend of our application.<\/p>\n<p>feel free to ask any thing confusing here. i will try my best to make it more simple, easy to understand as per your kind suggestions.<\/p>\n<p>Be blessed. Have a nice day.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/s06.flagcounter.com\/count\/iPxq\/bg=FFFFFF\/txt=000000\/border=FFFFFF\/columns=5\/maxflags=200\/viewers=0\/labels=1\/pageviews=1\/\" alt=\"free counters\" border=\"0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial is a part of series on application development of Amazon Kindle. This part describes the core concepts related to lifecycle of a kindlet (kindle application)<\/p>\n","protected":false},"author":1,"featured_media":5197,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[98,104,122,607,608,609,610,611,612,613,614,615,616,617,639,642,644,651,652,653,654,655,656,657,659,660,661,662,665,666,687],"class_list":["post-1387","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-amazon-kindle","tag-abstractkindlet","tag-active-content","tag-amazon-kindle-application-development-tutorial-part-3","tag-kdk-application-tutorial","tag-kdk-create","tag-kdk-destroy","tag-kdk-life-cycle","tag-kdk-loaded","tag-kdk-on-java","tag-kdk-ready-to-run","tag-kdk-running","tag-kdk-shutdown","tag-kdk-starts","tag-kdk-stop","tag-kindle-application-lifecycle","tag-kindle-create","tag-kindle-distroy","tag-kindle-lifecycle","tag-kindle-loaded","tag-kindle-on-java","tag-kindle-phases","tag-kindle-ready-to-run","tag-kindle-running","tag-kindle-shutdown","tag-kindle-start","tag-kindle-states","tag-kindle-stop","tag-kindle-tutorial","tag-kindlet","tag-kindlet-interface","tag-lifecycle-of-kindle-application"],"_links":{"self":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/1387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/comments?post=1387"}],"version-history":[{"count":3,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/1387\/revisions"}],"predecessor-version":[{"id":5198,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/1387\/revisions\/5198"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media\/5197"}],"wp:attachment":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media?parent=1387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/categories?post=1387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/tags?post=1387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}