0

I have a BaseActivity like bellow... Where My Interface global object on super class beame null.

public abstract class BaseActivity extends BaseTabActivity { 
          //did some implementation
}


public abstract class BaseTabActivity extends BasePickerActivity {
    //did some implementation
}

public abstract class BasePickerActivity extends Activity {
   // This is an interface
       private IOnImagSelected iOnImagSelected;

       public void imagePicker(IOnImagSelected iOnImagSelected){
           this.iOnImagSelected = iOnImagSelected;
       }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // process data and called iOnImagSelected

                  // Here I get null point which mean iOnImagSelected is null
                          iOnImagSelected.onImageSelected(imagepath)
        }
}

Now I have a Activity like

public class MyActivity extends BaseActivity implements IOnImagSelected {

       public void onPickImageClick(View v){
           imagePicker(this);
        }

     @Override
     poublic void onImageSelected(){

       }

}

Why My interface variable became null . Please help me with this

user3782810
  • 113
  • 1
  • 6

2 Answers2

1

I solved it its all hapening because of this option on my Google Nexus 7 developer settings

goto settings->Developer options

in that in APPS category(scroll down to see), see the option Don't keep Activities (Destroy every Activity as soon as user leabes it).

I found this from this post

That to that guy.:)

Community
  • 1
  • 1
user3782810
  • 113
  • 1
  • 6
0

You're passing one Activity, MainActivity to the BasePickerActivity but when BasePickerActivity is active MainActivity is null. Basically, your code is invalid; you ought to use Fragments for this sort of thing.

W.K.S
  • 9,787
  • 15
  • 75
  • 122
  • No You didnot get this I am passing a reference from MyActivity imagePicker() and IOnImagSelected this is an interface can't be create an object iOnImagSelected= new IOnImageSelected(); way.... – user3782810 Oct 20 '14 at 10:49
  • Please go through the code care fully be giving answers I am passing implemented interface not an activity. Please stop giving abswers. its not making any sence... – user3782810 Oct 20 '14 at 11:34
  • Firstly, there's no need to be rude. If my answers are wrong, just say so. Secondly, your interface references the activity so you are passing an activity. In your own answer, you enabled'Don't Destroy activities', so the activity is no longer null. However normal users don't have this enabled and your app will crash for them. You do need to use fragments! – W.K.S Oct 20 '14 at 12:41
  • You still don't get this its hapening because of in my developer oftion I make this one enabled that is why as soon as the activity start the previous get destroyed and global variable became null now I disabled this and its working perfectely and in your answer you says "when BasePickerActivity is active MainActivity is null." how could be be null ? my MainActivity is extends from base activity. – user3782810 Oct 20 '14 at 12:47