0

ALL, I am trying to understand why simple code like this:

device.setPhoto( bmp  );
Intent intent = new Intent( context, SexSelector.class );
intent.putExtra( "device", device );
    startActivity( intent );

does not start "SexSelector" activity, but goes back to the very first activity of the application.

I have minSdkVersion = 8 and targetSdkVersion = 19.

I tried surround this code with try/catch to no availability. It does not crashing. It just starts very first Activity of the applicatiActivity()" line.

And it does not even go to the SexSelector.java file.

I'm testing on the Samsung device with Android 4.2.2.

Here is the start of SexSelector class:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate( savedInstanceState );
    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    device = (Device) bundle.get( "device" );
    setContentView( R.layout.sex_selector );

The SexSelector activity is in the manifest. Once again the program does not crash, it just restarts.

Thank you for any hints.

Igor
  • 5,620
  • 11
  • 51
  • 103
  • 1
    try to comment `intent.putExtra("device", device);` and comment the related code in onCreate then run it, tell me what you get.. – Coderji May 17 '14 at 03:21
  • Instead of try/catch, see what the logcat says. – 323go May 17 '14 at 03:24
  • In sex selector class write code for intent, bundle and device after setcontentview – Siva May 17 '14 at 03:28
  • @323go, sendUserActionEvent() mView == null – Igor May 17 '14 at 03:28
  • But you wrote before setcontentview....write after contentview and check – Siva May 17 '14 at 03:30
  • @Coderji, commenting out those lines bring the proper activity. – Igor May 17 '14 at 03:32
  • @Siva, changing the place of the code didn't help. I still go to the very first activity. However commenting those lines as suggested by Coderji brought SexSelector activity on... – Igor May 17 '14 at 03:39
  • 1
    The problem is you are passing object through the bundle, bundle is designed to pass plain data only. check this [answer](http://stackoverflow.com/questions/4249897/how-to-send-objects-through-bundle) – Coderji May 17 '14 at 03:42
  • @Coderji, the class from which I have this object implements Parcelable. Is this not enough? Also I did check the link you gave me and I think I will use an "Application" approach as this should be an object for the whole life-cycle of the app. – Igor May 17 '14 at 05:42
  • I thought that this is all I need: implement Parcelable for the class, and use "putExtra()" call to pass the object between activities. Guess I was wrong.... – Igor May 17 '14 at 05:45
  • 1
    You can pass parcelable by using bundle, `bundle.setParelable("something", device);` and then you put bundle as extra in the intent.. hope this solves your problem, please give me a feedback – Coderji May 17 '14 at 06:44
  • @Coderji, I just tried to pass it this way and got a ClassCastException. Moreover, when the program starts I use the same code from the starting activity and it works. Now since this object should persist thru the lifecycle of the app, I think I will just override an Application class. In this case it will be accessible from any activity in application. Thank you. – Igor May 18 '14 at 09:31
  • Looking at this solution again I think it will complicate things because I will need to set some data to this object when it first created. So can you solve this mystery? Thank you. – Igor May 18 '14 at 09:35

0 Answers0