简体   繁体   中英

Passing object Bundle intent in Serializable class

I must mention i am new to Android and Java. I am trying this for a weeek to solve. I have Serializable class wich object are populated with http json, and i am using adapters to populate listviews and everything works fine but when i want to pass to another class one object i it force closes, please if somebody can correct my code.

this void is in Serializable class

  public void save(){
 Intent intent =  new Intent();
 Bundle extra = intent.getExtras();
  intent.putExtra("title", getTitle()); 

           }

when i try this:

Intent intent =  new Intent(this, Fragment2.class);  i got error The constructor   
Intent(FeedItem, Class<Fragment2>) is undefined

and this is fragment class where i want to use passed object

     Intent intent = getActivity().getIntent();
 Bundle extras = intent.getExtras();
 FeedItem feedItem = (FeedItem)getActivity().getIntent().getSerializableExtra("title");
 String title = feedItem.getTitle();
 Toast.makeText(getActivity(), title, Toast.LENGTH_LONG).show(); 

error The value of the local variable extras is not used

Many thanks.

Fragments are added like this

FragmentTransaction ft = getSupportFragmentManager()
                    .beginTransaction();
            ft.replace(resourceidwhereyouwantadd(R.id.view), new YourFragment());
            ft.commit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM