Jeff Hines, Kindle Fire test team, and Chirag Mehta, Manager, a2z Developer Center Inc., an Amazon.com company, are our bloggers for this post.
This post is the first in a series detailing the top 10 optimizations to improve your app on Kindle Fire. These posts are designed to provide you with solutions, sample code, and the opportunity to address common issues that can arise as you optimize your app for Kindle Fire.
The first topic in this series reviews one of the most frequently asked questions when developing on Kindle Fire: “My app is not optimized to interact with Kindle Fire Quick Settings, what can I do to provide a better customer experience?”
The Quick Settings feature is unique to the device and provides Kindle Fire owners with a host of easily accessible options, including Volume, Brightness, Wi-Fi, and more. The image below shows the Quick Settings feature and its location on the device. Like the soft key bar, the Quick Settings feature is visible at all times, including when your app is running. When optimizing for Kindle Fire, your app should account for users accessing the Quick Settings bar at any time while your app is running.
Invoking the Quick Settings feature should not affect the app or its current state. Some apps, like most games, should simply pause. Other apps that are more static in nature, and rely on user interaction to change state, can simply run in the background.
If your app is not optimized for Kindle Fire and does not take into account a user interacting with the Quick Settings bar, the following scenarios could result:
The following code snippets (based on a set of sample apps) show you how you can optimize your app for the Quick Settings feature.
This sample code shows how your app could pause if a user invokes the Quick Settings. The code saves the label position on screen, and save the score. The onPause() call is highly recommended, as it ensures your app saves its state.
protected void pause() {
final Editor editor = m_state.edit();
editor.putLong("xMove", m_xMove);
editor.putLong("yMove", m_yMove);
editor.putLong("xPos", m_xPos);
editor.putLong("yPos", m_yPos);
editor.putLong("score", m_score);
editor.commit();
// Stop the animation thread.
if (m_animationThread != null) {
m_animationThread.setRunning(false);
m_animationThread = null;
}
}
This sample code shows how your app could resume after a user leaves the Quick Settings. The code initializes a label, determines its position on screen, and displays the score. The onResume() call is highly recommended, as it ensures your app resumes its state.
protected void resume() {
m_paint = new Paint();
m_random = new Random();
m_state = m_context.getSharedPreferences("UserState", Context.MODE_PRIVATE);
m_xMove = m_state.getLong("xMove", DEFAULT_X_MOVEMENT);
m_yMove = m_state.getLong("yMove", DEFAULT_Y_MOVEMENT);
// Set initial position of the score to the center of the screen.
m_xPos = m_state.getLong("xPos", this.getWidth() / 2);
m_yPos = m_state.getLong("yPos", this.getHeight() / 2);
m_score = m_state.getLong("score", DEFAULT_SCORE);
// Start the thread if it has been previously stopped.
if (m_animationThread == null) {
m_animationThread = new AnimationThread(getHolder(), this);
m_animationThread.setRunning(true);
m_animationThread.start();
}
}
Many games having actively running animations and it’s essential to pause and retain animation state when a user invokes the Quick Settings.
public class PausingAnimationSampleActivity extends Activity {
/** Reference to the content view, used to pause and resume the animation */
private AnimationPanel m_panel;
/** {@inheritDoc} */
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_panel = new AnimationPanel(this);
setContentView(m_panel);
}
/** {@inheritDoc} */
@Override
protected void onStart() {
super.onStart();
}
If your app pauses its animations sequences using the sample above, you can resume the animation sequence using the sample code below.
@Override
protected void onPause() {
super.onPause();
m_panel.pause();
}
/** Restore the user's state when returning to the application */
@Override
protected void onResume() {
super.onResume();
m_panel.resume();
}
/** {@inheritDoc} */
@Override
protected void onStop() {
super.onStop();
}
}
See the Amazon App Developer FAQ if you have more questions.
This is only the first of ten optimizations in our new series, so be sure to check back for our next post on layout and the soft key bar!
Top 10 App Optimizations for Kindle Fire – Part I
This post is the first in a series detailing the top 10 optimizations to improve your app on Kindle Fire. These posts are designed to provide you with solutions, sample code, and the opportunity to address common issues that can arise as you optimize your app for Kindle Fire.
The Quick Settings feature is unique to the device and provides Kindle Fire owners with a host of easily accessible options, including Volume, Brightness, Wi-Fi, and more. The image below shows the Quick Settings feature and its location on the device. Like the soft key bar, the Quick Settings feature is visible at all times, including when your app is running. When optimizing for Kindle Fire, your app should account for users accessing the Quick Settings bar at any time while your app is running.
Invoking the Quick Settings feature should not affect the app or its current state. Some apps, like most games, should simply pause. Other apps that are more static in nature, and rely on user interaction to change state, can simply run in the background.
If your app is not optimized for Kindle Fire and does not take into account a user interacting with the Quick Settings bar, the following scenarios could result:
· Your app could force close or become unresponsive
· Your app’s state or user save data may become lost or reset
· Your app’s video or audio may become reset or interrupted
· Your app may enter an unrecoverable state such as perpetual loading or black screen
· Your app continues to actively run and does not enter a paused state
The following code snippets (based on a set of sample apps) show you how you can optimize your app for the Quick Settings feature.
This sample code shows how your app could pause if a user invokes the Quick Settings. The code saves the label position on screen, and save the score. The onPause() call is highly recommended, as it ensures your app saves its state.
protected void pause() {
final Editor editor = m_state.edit();
editor.putLong("xMove", m_xMove);
editor.putLong("yMove", m_yMove);
editor.putLong("xPos", m_xPos);
editor.putLong("yPos", m_yPos);
editor.putLong("score", m_score);
editor.commit();
// Stop the animation thread.
if (m_animationThread != null) {
m_animationThread.setRunning(false);
m_animationThread = null;
}
}
This sample code shows how your app could resume after a user leaves the Quick Settings. The code initializes a label, determines its position on screen, and displays the score. The onResume() call is highly recommended, as it ensures your app resumes its state.
protected void resume() {
m_paint = new Paint();
m_random = new Random();
m_state = m_context.getSharedPreferences("UserState", Context.MODE_PRIVATE);
m_xMove = m_state.getLong("xMove", DEFAULT_X_MOVEMENT);
m_yMove = m_state.getLong("yMove", DEFAULT_Y_MOVEMENT);
// Set initial position of the score to the center of the screen.
m_xPos = m_state.getLong("xPos", this.getWidth() / 2);
m_yPos = m_state.getLong("yPos", this.getHeight() / 2);
m_score = m_state.getLong("score", DEFAULT_SCORE);
// Start the thread if it has been previously stopped.
if (m_animationThread == null) {
m_animationThread = new AnimationThread(getHolder(), this);
m_animationThread.setRunning(true);
m_animationThread.start();
}
}
Many games having actively running animations and it’s essential to pause and retain animation state when a user invokes the Quick Settings.
public class PausingAnimationSampleActivity extends Activity {
/** Reference to the content view, used to pause and resume the animation */
private AnimationPanel m_panel;
/** {@inheritDoc} */
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
m_panel = new AnimationPanel(this);
setContentView(m_panel);
}
/** {@inheritDoc} */
@Override
protected void onStart() {
super.onStart();
}
If your app pauses its animations sequences using the sample above, you can resume the animation sequence using the sample code below.
@Override
protected void onPause() {
super.onPause();
m_panel.pause();
}
/** Restore the user's state when returning to the application */
@Override
protected void onResume() {
super.onResume();
m_panel.resume();
}
/** {@inheritDoc} */
@Override
protected void onStop() {
super.onStop();
}
}
This post is the first in a series detailing the top 10 optimizations to improve your app on Kindle Fire. These posts are designed to provide you with solutions, sample code, and the opportunity to address common issues that can arise as you optimize your app for Kindle Fire.
The Quick Settings feature is unique to the device and provides Kindle Fire owners with a host of easily accessible options, including Volume, Brightness, Wi-Fi, and more. The image below shows the Quick Settings feature and its location on the device. Like the soft key bar, the Quick Settings feature is visible at all times, including when your app is running. When optimizing for Kindle Fire, your app should account for users accessing the Quick Settings bar at any time while your app is running.
See the Amazon App Developer FAQ if you have more questions.
This is only the first of ten optimizations in our new series, so be sure to check back for our next post on layout and the soft key bar!