i use this code to set from a preferences screen, if i want show the notifications or not. The problem is that this code works only if i create a button to go on preferences screen. I want go on preferences with my sub-menu "settings" button and not a button inside my layout. Thsi is the code
       // prefer
         setPref.setOnClickListener(new Button.OnClickListener(){    
                @Override    
                public void onClick(View arg0) {     
                    // TODO Auto-generated method stub   
                    Intent intent = new Intent(
                            MainActivity    .this, 
                            settings.class);
                    startActivityForResult(intent, 0);
                }});         
            checkPref();
        }
        @SuppressLint("NewApi")
        private void checkPref(){
            SharedPreferences myPref 
            = PreferenceManager.getDefaultSharedPreferences(
                    MainActivity.this);
            boolean pref_opt1 = myPref.getBoolean("pref_opt1", false); 
            if (pref_opt1){
                NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
                Notification notification = new Notification.Builder(getApplicationContext())
                .setContentTitle("Battery Informations")
                .setContentText("Batteria al")
                .setSmallIcon(R.drawable.icon_small_not)
                //.setLargeIcon(aBitmap)
                .setTicker("Livello")
                .build();
                notification.flags = Notification.FLAG_ONGOING_EVENT;
                Intent i = new Intent(MainActivity.this, MainActivity.class); 
                PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0);
                notifi.notify(215,notification);
                } else {
                NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
                notifi.cancel(215);
                }
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, data);
            checkPref();
    }
How can i do it?
 
     
     
     
    