Android Intent and Intent filter

353 views Asked by At

I have a problem here with my code. I want to pass from an activity to another from a button. Here is my code:

MainActivity.class

ImageView imgsettings;

inside onCreate()

imgsettings = (ImageView) findViewById(R.id.imgviewsettings);
imgsettings.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        startActivity(new Intent("android.intent.action.SETTINGS"));                                
    }
});

AndroidManifest

<activity
    android:name=".AppSettings"
    android:label="@string/title_activity_app_settings" >
    <intent-filter>
        <action android:name="android.intent.action.SETTINGS" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter> 
</activity>

I really cannot find the problem. Everything seem right to me.

3

There are 3 answers

5
Gabriella Angelova On BEST ANSWER

There is no action with the name android.intent.action.SETTINGS. Try to remove the <intent-filter> from your manifest and add this code snippet in the onClick() method:

Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

Take a look at this SO question Opening Android Settings programmatically

1
Nilay Dani On

You don't have to deal with for this. You have to do startActivity(new Intent(MainActivity.this,AppSettings.class)); to go to AppSettings activity.

2
Prabhuraj On

Try this in your onClick method.

 Intent myIntent = new Intent(MainActivity.this, android.intent.action.SETTINGS.class);

MainActivity.this.startActivity(myIntent);