Need To Display The Result In New Activity
Solution 1:
Try this :
In MainActivity :
Intent intent = newIntent();
intent.setClass(this, Other_Activity.class);
intent.putExtra("EXTRA_ID", "SOME DATAS");
startActivity(intent);
In Other_Activity :
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String datas= extras.getString("EXTRA_ID");
if (datas!= null) {
// do stuff
}
}
Also check this : Android Intents
Hope this helps.
Solution 2:
To start a new activity, you simply use Intents. For example, if you want to start an activity that is stored in NewActivity.java
from your current activity, use this:
Intent i = newIntent(this, NewActivity.class);
i.startActivity();
However, if you want to parse data from one activity to another you need to use arguments. For example, if your ouptut is in the temp
variable of your main activity, use this to pass it to the new activity:
Intent i = newIntent(this, NewActivity.class);
i.putExtra("output", temp);
i.startActivity();
Then from the onCreate()
method of your new activity retrieve the String via:
String result= getIntent().getStringExtra("output");
Toast.makeText(getActivity(), "You are " +result, Toast.LENGTH_SHORT).show();
Solution 3:
Assuming you want to print result when submit button is clicked, do following steps.
Create intent for intended activity
Intent intent = newIntent(MainActivity.this, OtherActivity.class);
- Set result to that intent
intent.putExtra("key", value);
Start new activity
startActivity(intent);
Get result in other activity
intvalue = getIntent.getExtras.get("key"); // not necessarily int, any value
Display result in any
Textview
textView.setText(""+value);
Solution 4:
What you are asking it is not clear but I think what you need is startActivityForResult
Post a Comment for "Need To Display The Result In New Activity"