Skip to content Skip to sidebar Skip to footer

How Do I Get Extra From An Intent (as A Type Long)?

I have this problem accessing an extra from an intent. The value i'm parsing is a long type, and I need this value to be stored in a database. So this is what I have so far: MainAc

Solution 1:

Move fetchDate = getIntent(); inside onCreate method of Activity as:

protectedvoidonCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.create);
     //.your code here..
    fetchDate = getIntent();  // get intent here from previous ActivitylongdateFecth= fetchDate.getLongExtra(DATE, defaultValue);
}

Solution 2:

First check - Value is associated with the given name. if you don't want to use defaultValue try with bundle as follow

if (getchDate.hasExtra("Date"))  {
Bundle bundle = newBundle();
bundle =  getchDate.getExtras();
Objectobject = bunlde.get(Date);
Now parse thisobjectin your desire type.

}

Solution 3:

You should check if result of getIntent() is not empty at first (an of course the call should be inside onCreate, not constructor). If it's not empty, then get long variable from it. defaultValue stands for a value returned from a method if a value for specified key is not found.

Post a Comment for "How Do I Get Extra From An Intent (as A Type Long)?"