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

How to re-join a XMPP group/room after login in android using smack 4.1
Display the pdf file(stored in google drive) in webview by using google docs
Android. Button does not work in Canvas
Add rows and keys at run time to custom keyboard in android
Error where creating a SessionSlack with bot user auth token: Item may not be null
Scrollable Tab bar cannot restore when other tab clicked
Xamarin android splash screen. Disallow input
not able to build ionic project with CordovaLib:processDebugResources FAILED error
An error occurred when Android emulator Genymotion load so file
Push notification for uploading new video in Youtube in Android app
Android Studio- where the library classes are stored
Statusbar is not transparent but white
FloatingActionButton appearing under screen when using TabLayout and ViewPager
Safe/Easy way to update Parcelable
Me recycler view comes on top of the navigation drawer
App not running on Hardware Device in Android Studio

Categories

HOME
beautifulsoup
ecmascript-6
flex
fftw
hugo
mapbox
accessibility
openstreetmap
openpyxl
heap
startup
mxgraph
spring-social
plink
package-managers
feathersjs
wolframalpha
google-container-registry
pyramid
poedit
question2answer
visual-studio-extensions
dapper-extensions
custom-post-type
flooding
amazon-quicksight
entity-relationship-model
userdefaults
memory-address
autolisp
gnat-gps
pdw-file-browser
processwire
openerp-7
parse-tree
openproject
dm-script
modernizr
file-sharing
uiimage
plan-9
sonarlint-eclipse
static-cast
azure-cli
subnet
arules
bbpress
restore
mongodb-php
windows-azure-queues
model-associations
deep
libvlc
directdraw
ember-cli-rails
openbabel
qtwebengine
adehabitathr
exceldatareader
infosphere-spl
rapidsvn
at-job
android-vibration
post-commit-hook
universal-image-loader
mintty
lnk
functional-java
dct
spring-remoting
file-not-found
inputmismatchexception
process-explorer
mysql-error-2013
fb.ui
httponly
failing-tests
nhprof
luajava
lxr
data-mapping
tui
mathematical-notation
windows-identity
firefox-3
soappy
httpcookie
wcf-proxy

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