0

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.

Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41

3 Answers3

0

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.

Nilay Dani
  • 896
  • 6
  • 24
  • I did it. I wrote: public void onClick(View v) { intent = new Intent(MainActivity.this, AppSettings.class); startActivity(intent); } It still gives me an error: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.oldie.AppSettings}:java.lang.NullPointexception – Εμμανουήλ Βαρέσης Jun 19 '15 at 13:51
0

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

Community
  • 1
  • 1
Gabriella Angelova
  • 2,985
  • 1
  • 17
  • 30
0

Try this in your onClick method.

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

MainActivity.this.startActivity(myIntent);
Prabhuraj
  • 928
  • 2
  • 8
  • 14