Home > Uncategorized > How to Control/Disable Home Button

How to Control/Disable Home Button

All Technical Solution – Disable Home Button in Android

You can’t control the home button as now, You can not disable the home button, you need to write your own firmware bla..bla..

But you can control you Home Button, disable you Home button.

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
<application android:icon=”@drawable/icon” android:label=”@string/app_name”>
<activity android:name=”.SavedInstace”
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.HOME” />
<category android:name=”android.intent.category.DEFAULT” />
<category android:name=”android.intent.category.MONKEY”/>
<category android:name=”android.intent.category.LAUNCHER” />

<activity android:name=”Activity2″></activity>

<uses-permission android:name=”android.permission.SET_PREFERRED_APPLICATIONS”/>

<uses-sdk android:minSdkVersion=”5″ />

package com.ssc.save.instance;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

* We have two activity Activity1 and Activity2
* In Activity1, have two EditText field and a Save button
* clicking on Save button, Activity2 get called and click of submit Button of Activity2,
* Activity1 get called.
* Now I want to preserve the Activity1 data, while moving to Activity2, and vice versa
public class SavedInstace extends Activity {
/** Called when the activity is first created. */
Button submit;
EditText et1;
EditText et2;
Bundle savedInstanceState;
private static final String TAG = “SavedInstace”;

public void onCreate(Bundle savedInstanceState) {
// this.savedInstanceState = savedInstanceState;
submit = (Button) findViewById(R.id.submit);
et1 = (EditText) findViewById(R.id.et_one);
et2 = (EditText) findViewById(R.id.et_two);
String one = getIntent().getStringExtra(“one”);
String two = getIntent().getStringExtra(“two”);
if ((one == null) || (two == null)) {
// do nothing
} else {
one = getIntent().getStringExtra(“one”);
two = getIntent().getStringExtra(“two”);
et1 = (EditText) findViewById(R.id.et_one);
et2 = (EditText) findViewById(R.id.et_two);
// if (savedInstanceState != null) {
// String one = null;
// String two = null;
// one = savedInstanceState.getString(“one”);
// two = savedInstanceState.getString(“two”);
// et1 = (EditText) findViewById(R.id.et_one);
// et2 = (EditText) findViewById(R.id.et_two);
// et1.setText(one);
// et2.setText(two);
// }
// Set as home activity
// This is done so we can appear to disable the Home key.
PackageManager pm = getPackageManager();

IntentFilter filter = new IntentFilter(“android.intent.action.MAIN”);

ComponentName[] components = new ComponentName[]
new ComponentName(“com.android.launcher”, “.Launcher”)

Context context = getApplicationContext();
ComponentName component = new ComponentName(context.getPackageName(),

pm.addPreferredActivity(filter, IntentFilter.MATCH_CATEGORY_EMPTY,
components, component);

submit.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Intent activity2 = new Intent(SavedInstace.this,
String one = et1.getText().toString();
String two = et2.getText().toString();
activity2.putExtra(“one”, one);
activity2.putExtra(“two”, two);
startActivityForResult(activity2, 0);

protected void onPause() {
Log.d(TAG, “onPause”);

protected void onResume() {
Log.d(TAG, “onResume”);


protected void onRestart() {
Log.d(TAG, “onRestart”);
// onRestoreInstanceState(savedInstanceState);

protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
Log.d(TAG, “onSaveInstanceState”);
String one = null;
String two = null;
boolean b = false;
et1 = (EditText) findViewById(R.id.et_one);
et2 = (EditText) findViewById(R.id.et_two);
one = et1.getText().toString();
two = et2.getText().toString();

outState.putString(“one”, one);
outState.putString(“two”, two);

protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
Log.d(TAG, “onRestoreInstanceState”);
if (savedInstanceState != null) {
String one = null;
String two = null;
one = savedInstanceState.getString(“one”);
two = savedInstanceState.getString(“two”);
et1 = (EditText) findViewById(R.id.et_one);
et2 = (EditText) findViewById(R.id.et_two);


public class SavedInstaceHolder {


Categories: Uncategorized
  1. June 8, 2011 at 11:19 am

    This is horrible code. Do not request the HOME category unless *you are a home screen*. SDK applications cannot call clearPackagePreferredActivities() except for their own package. onSaveInstanceState() does not need to manually handle EditText widgets, as the built-in implementation handles those for you. And so on.

  2. Gaurav
    July 30, 2011 at 8:15 am

    Thank Dude…….. Great job 🙂

  3. January 3, 2012 at 8:54 pm

    Thanks!, that was the answer to my question in stackoverflow, some people laugh of me, haha http://stackoverflow.com/questions/8715658/how-i-cant-avoid-both-the-app-close-and-the-go-in-background/8716135#8716135

    maybe you can use some code plugin 😉 in this post

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: