android


Sending a parameter from activity1 to Activity2


In my android application i want to send the value of EditText from an Activity1 to Activity2 to be used there ..What can i do please??
//This is my first Activity
public class registrer extends Activity {
EditText ET_USER_NAME,ET_USER_PASS,ET_USER_CONFIRM;
Button btsuivant;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registrer);
ET_USER_NAME=(EditText)findViewById(R.id.new_user_name);
Intent intent = new Intent(this,CreerCV3.class);
intent.putExtra("Key1", ET_USER_NAME.getText().toString());
}}
// the CreerCV3
public class CreerCV3 extends Activity {
String user_name,user_pass,user_confirm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_creer_cv3);
Intent intent=getIntent();
String s=intent.getStringExtra("Key1");
TextView t=(TextView)findViewById(R.id.ob);
t.setText(s);
}}
//xml of the textviex
android:id="#+id/ob" />
//xml of the editText (regiter)
seems like everthing is ok but when i run the app there is no text displayed.....
In First Activity you can do like below...
Intent intent = new Intent ( FirstAcvity.this, SecondActivity.class );
intent.putExtra ( "TextBox", editText.getText().toString() );
startActivity(intent);
In second activity, use following...
Intent i = getIntent();
String text = i.getStringExtra ( "TextBox","" );
Hope this will help...
You can use intent and putextra() in your first activity like below:
in activity one:
EditText editText;
editText=(EditText) findViewById(R.id.new_user_name);
Intent intent = new Intent(this,activity2.class);
intent.putExtra("key",editText.getText().toString());
startActivity(intent);
in activity two:
Intent intent=getIntent();
String s=intent.getStringExtra("key");
Toast.makeText(this,s,Toast.LENGTH_SHORT).show();
Have you read the "Build your first app" section of android developers site? The task you are asking about is quite well explained there!
from
http://developer.android.com/training/basics/firstapp/starting-activity.html
//build you intent to start the activity
Intent intent = new Intent(this, DisplayMessageActivity.class);
//take the text from your edittext
String message = yourEditText.getText().toString();
//add that text as an extra to the activity
intent.putExtra(EXTRA_MESSAGE, message);
//start the Activity
startActivity(intent);
that's all!!

Related Links

Android developers guide [duplicate]
Android: is screen “flickering” harmful?
Solve run time errors
Android: WebView onClick not work?
Canvas drawables and centered zooming
Set Wallpaper from webview URL
Install app from Eclipse to /system/app at compile time
Phonegap / Android App - Loss of web connectivity switching from wifi / data?
Why does my code keep giving me a null pointer exception? [Android in Eclipse]
How can i get the nearest location by using google map api in android?
Issues while image downloading
Handle synchronisation of data between Android Service and Server via REST API
Android - stackoverflow Error
Sorting ListBiew by Spinner in android?
PhoneGap speed vs native iOS 4/5 and Android for GPS / Location Services / Maps
I want toast message to be displayed when alarm rings for android

Categories

HOME
fabricjs
github-for-windows
depth
interface
apache-spark-mllib
solaris
solver
vimdiff
plist
windows-ce
line
speech-synthesis
glyphicons
feathersjs
easyphp
poedit
babel
interpreter
strongname
onload
slidetoggle
jquery-multiselect
appirater
oculus
linked-data
sqlpackage
utorrent
keras-layer
installscript
protege4
sim-toolkit
magento-1.9.2.4
lint
xdocreport
ogc
azure-arm
odoo-website
congestion-control
file-sharing
dapper-simplecrud
procfile
puredata
rserve
reindex
boxing
payload
type-theory
gpg-signature
rocks
mapxtreme
google-cloud-console
dotnetnuke-7
signalr.client
rspec2
model-associations
drawstring
x-tag
pre-build-event
qiime
beanstalk
halcon
httpruntime.cache
toast
jaunt-api
crouton-os
highland.js
qt5.2
doctype
google-refine
android-cookiemanager
mruby
browserify-shim
with-statement
build-script
kissfft
xml-dsig
jquery-slider
android-framework
inappsettingskit
mvc-editor-templates
cardreader
swfobject
idn
listitem
filemerge
update-statement
entitydatasource
drawtobitmap
massive
cuteeditor
http-daemon
commerceserver2007
globals
tabpanel
murmurhash
purepdf
wcf-instancing
interop-domino
unmanagedresources
appliance

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App