0

i'm trying to develope an app for a tablet (ICS 4.0.3) that will be used in public places like bar, resturant ecc..

The user that uses that tablet ( so my application ) could not go in home and only administrator, setting a code, can go out.

What i've done is:

public class MainActivity extends Activity {
    private Activity actual;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        if (getIntent().getBooleanExtra("EXIT", false)) {
           finish(); // it doesn't work 
        }
    }
    @Override
    public void onBackPressed() {
        // do nothing!
    }
}

MANIFEST:

<activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name"
            android:screenOrientation="landscape" >
            <intent-filter>
                <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"/>
            </intent-filter>
        </activity>

ADMINISTRATION DIALOG:

TEST1: // application is relaunched

Intent homeIntent= new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(homeIntent);

TEST2: // application is relaunched

System.exit(0);

TEST3: // it open settings (o.O)

Intent h = new Intent(Intent.ACTION_MAIN);
h.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
h.putExtra("EXIT", true);
context.startActivity(h);

My problem is that i can't go out from application.. how can i solve?

Jayyrus
  • 12,961
  • 41
  • 132
  • 214

1 Answers1

0

In TEST3 you've only provided ACTION_MAIN in the Intent. Android looks for apps that can handle this action and finds a long list of them. How should it know that it should launch yours?

I assume you've set your app as a HOME-screen replacement. Try adding this to the code for TEST3:

h.addCategory(Intent.CATEGORY_HOME);
David Wasser
  • 93,459
  • 16
  • 209
  • 274