开发者

error while passing data from one activity to other and displaying in a tablelayout

开发者 https://www.devze.com 2023-03-30 14:55 出处:网络
hi i am passing the latitude,longitude and address using a bundle to another activity. in another activity i am retrieving data from the bundle. but when i click the button on which bundle is used the

hi i am passing the latitude,longitude and address using a bundle to another activity. in another activity i am retrieving data from the bundle. but when i click the button on which bundle is used the app crashes. i cant post the logcat as nothing comes in ddms. i m using the device debug mode. heres my code:

                   Bundle b=new Bundle();
                   b.putString("latitude", lat+"");
                   b.putString("longitude", lon+"");
                       b.putString("address", result1);
                   Intent i=new Intent(Cortes.this,Display.class);      
                   i.putExtras(b);
                   startActivity(i)  ;

i am w开发者_JAVA技巧riting this in listener of button and Display is the another activity. in that activity my code is:

Bundle b=this.getIntent().getExtras();
latitude=b.getString("latitude");
longitude=b.getString("longitude");
address=b.getString("address");

i am displaying db in that activity in a tablelayout. cursor for that i have written in another activity named Display.in cursor i am using the values which i am passing to another activity

pls help


try this

Bundle b = getIntent.getExtras();

or

Bundle b = ClassName.this.getIntent.getExtras();


retrieve data like this:

Bundle var_name = getIntent().getExtras().getBundle(key);


If you use a custom Bundle, it seems there is some requirements, according to the doc:
The keys must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".
The common way I know to share data between activities is to use the default Intent bundle to store them, like this:

Intent i=new Intent(Cortes.this,Display.class);      
i.putExtra("latitude", lat+"");
i.putExtra("longitude", lon+"");
i.putExtra("address", result1);
startActivity(i);

Then, you retrieve the infos like this:

Intent i=this.getIntent();
latitude=i.getStringExtra("latitude");
longitude=i.getStringExtra("longitude");
address=i.getStringExtra("address");
0

精彩评论

暂无评论...
验证码 换一张
取 消