I have two activities such as Activity A and B and I'm trying to pass two different strings from A to B using Bundle and startActivity(intent).
Like that:
Intent intent = new Intent(A.this, B.class);
Bundle bundle = new Bundle();
bundle.putString("vidoedetails", filedetails);
//bundle.putString("videoname", filename);
intent.putExtras(bundle);
//intent.putExtra("videofilename", filename);
//intent.putExtra("vidoefiledetails", filedetails);
startActivity(intent);
And in class B I'm using two TextViews to display the strings from class A seperately.
Like that:
Intent i = getIntent();
Bundle extras = i.getExtras();
filedetails = extras.getString("videodetails");
filename = extras.getString("videoname");
The problem is filedetils get printed in class B but not the file name.
Any solution for this?
you have a typo:
bundle.putString("vidoedetails", filedetails);
should be
bundle.putString("videodetails", filedetails);
I know I am 9 days late on this answer, but this is a good example of why I create a constants class. With a constants class, it doesnt matter if it is misspelled ("video" -> "vidoe") because it will be 'misspelled' in both places as you are referencing it through a well known location.
Constants.java
public static String WELL_KNOWN_STRING "org.example.stackoverflow.4792829";
Activity1.java
bundle.putString(Constants.WELL_KNOWN_STRING, filedetails);
Activity2.java
filedetails = extras.getString(Constants.WELL_KNOWN_STRING);
Yes, you spelled wrongly videodetails:
Yours: vid*OE*details
Correct: vid*EO*details
// First activity
actvty_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(v.getContext(),SECONDACTIVITY.class);
startActivityForResult(i, STATIC_INTEGER_VALUE);
}
});
/* This function gets the value from the other activity where we have passed a value on calling this activity */
public void activity_value() {
Intent i = getIntent();
Bundle extras=i.getExtras();
if(extras !=null) {
// This is necessary for the retrv_value
rtrv_value = extras.getString("key");
if(!(rtrv_value.isEmpty())) {
// It displays if the retrieved value is not equal to zero
myselection.setText("Your partner says = " + rtrv_value);
}
}
}
// Second activity
myBtn.setOnClickListener(new View.OnClickListener () {
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), FIRSTACTIVITY.class);
Bundle bundle = new Bundle();
bundle.putString("key", txt1.getText().toString());
// Here key is just the "Reference Name" and txt1 is the EditText value
intent.putExtras(bundle);
startActivity(intent);
}
});
Here's another way to pass data between Activities. This is just an example from a tutorial I was following. I have a splash screen that runs for 5 seconds and then it would kill the sound clip from:
#Override
protected void onPause() {
super.onPause();
ourSong.release();
}
I decided I wanted the sound clip to continue playing into the next activity while still being able to kill/release it from there, so I made the sound clip, MediaPlayer object, public and static, similar to how out in System.out is a public static object. Being new to Android dev but not new to Java dev, I did it this way.
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
public static MediaPlayer ourSong; // <----- Created the object to be shared
// this way
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.dubstep);
ourSong.start();
Thread timer = new Thread() {
public void run() {
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openStartingPoint = new Intent(
"expectusafterlun.ch.androidtutorial.MENU");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
}
Then from the next activity, or any other activity, I could access that MediaPlayer object.
public class Menu extends ListActivity {
String activities[] = { "Count", "TextPlay", "Email", "Camera", "example4",
"example5", "example6" };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,
android.R.layout.simple_expandable_list_item_1, activities));
}
#Override
protected void onPause() {
super.onPause();
Splash.ourSong.release(); // <----- Accessing data from another Activity
// here
}
}
Related
I want to define callback for a Notebook program that way after note saved in EditActivity,in Main Activity Update list of notes,But This does not happen.
EditActivity:
public interface OnClickDoneListener{
void onClickDone();
}
public void setOnClickDoneListener(OnClickDoneListener onClickDoneListener){
this.onClickDoneListener=onClickDoneListener;
}
btnDone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (extras != null) {
myDatabase.updateRow(id, txtTitle.getText().toString(), txtDesc.getText().toString());
NoteModel noteModel = new NoteModel();
noteModel.setTitle(txtTitle.getText().toString());
noteModel.setDesc(txtDesc.getText().toString());
Intent intent = new Intent(EditActivity.this, MainActivity.class);
startActivity(intent);
onClickDoneListener.onClickDone();
} else {
Done();
}
}
});
Main Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setupViews();
getDataFromDB();
recyclerView.setAdapter(new NoteAdapter(MainActivity.this,dataList));
noteAdapter = new NoteAdapter(MainActivity.this,dataList);
recyclerView.setAdapter(noteAdapter);
fabAdd = (FloatingActionButton)findViewById(R.id.fab_main_add) ;
EditActivity editActivity = new EditActivity();
editActivity.setOnClickDoneListener(new EditActivity.OnClickDoneListener() {
#Override
public void onClickDone() {
noteAdapter.notifyDataSetChanged();
}
});
please help me.
My English is poor,sorry for it.
You want your data to be updated when the MainActivity is shown, right ?
You just have to call your getDataFromDB part in onResume() instead of onCreate()
EditActivity editActivity = new EditActivity();
editActivity.setOnClickDoneListener(new EditActivity.OnClickDoneListener() {
#Override
public void onClickDone() {
noteAdapter.notifyDataSetChanged();
}
});
What you are doing here is setting the value of OnClickDoneListener in a new instance of EditActivity that you will never use. Because when you use new Intent(MainActivity.this, EditActivity.class) to start the EditActivity it will create a new instance of EditActivity and your interface would be null.
I suggest you use android's Broadcast Receiver instead of a callback in this case. All you have to do is:
In MainActivity: You will need to instantiate a broadcast receiver. You need to register it onCreate or onStart and unregister it onStop or onDestory.
In EditAcitivity: You send a broadcast whenever you want to notify your MainActivity to update the list.
Check out this example:
https://riptutorial.com/android/example/18305/communicate-two-activities-through-custom-broadcast-receiver
I have Act_01 (where I put value) and Act_02 (where I get value) but have declared these methods in a Extras class, getting value from Act_02 returns null value:
Act_01: (Where I want to pass the value Name to Act_02)
public class Act_01 extends Activity {
Extras cc_Extras;
Button btn1;
Intent intent;
String str_Name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_01);
cc_Extras = new Extras();
str_Name = "Buck";
btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
cc_Extras.putExtras();
startActivity(intent);
}
});
}
}
Act_02: (Where I want ot receive value Name from Act_01 but the app crashes with null value)
public class Act_02 extends Activity {
Extras cc_Extras;
String str_Name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_02);
cc_Extras = new Extras();
if(getIntent() != null && getIntent().getExtras() != null)
{
cc_Extras.getExtras();
}
Toast.makeText(getApplicationContext(), "Name: "+str_Name, Toast.LENGTH_SHORT).show();
}
}
Extras: (Where I define the methods to put and get Extras)
public class Extras extends Activity {
String str_Name;
Intent intent;
public void putExtras() {
// TODO Auto-generated method stub
intent.putExtra("KEY_Name", str_Name);
}
public void getExtras() {
// TODO Auto-generated method stub
str_Name = getIntent().getExtras().getString("KEY_Name");
}
}
EDIT: I do not want to pass and get data directly between activities, I want to use the 3rd class (Extras.java) because I have too many activities having too many values between each other and want to sort of define them globally in Extras so that all my other activities can just call one method instead of getting and putting too many values in my activities.
Your app crashes not with a null value, but a null pointer reference because you created a new Activity manually
cc_Extras = new Extras();
Then called a lifecycle method on it
cc_Extras.getExtras()
Which calls getIntent(), but the Intent was never setup by the Android framework, and cc_Extras.getExtras() wouldn't have any of the data you wanted anyway in the second Activity because it was just created there, not from the first Activity.
Briefly, you should never make a new Activity, and your Extras class does not need to be an Activity in the first place (nor does it provide much benefit).
Just use the Intent object provided by the first Activity to start the second Activity, and get extras like normal. Don't overcomplicate your code. Regarding the title of the question, Intent and Bundle are already "another class" designed by Android for you to transfer data.
On both activities you are creating a new instances of Extras class means they dont hold the same value you can do this to transfer data from A to B
public class Act_01 extends Activity {
Button btn1;
Intent intent;
String str_Name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_01);
str_Name = "Buck";
btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
intent = new Intent(Act_01.this, Act_02.class);
intent.putExtra("data", str_Name)
startActivity(intent);
}
});
}
}
And receieve data like this
public class Act_02 extends Activity {
String str_Name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_02);
// cc_Extras = new Extras();
if(getIntent() != null)
{
if (getIntent().getStringExtra("data") != null) {
Toast.makeText(Act_02.this, "Name: "+getIntent.getStringExtra("data"), Toast.LENGTH_SHORT).show();
}
}
}
}
Also you should consider using Activity Context instead of the application context
Ok! so here are the few things I might wanna suggest you to correct.
Changes needs to be done in the code.
You are not assigning anything to "intent" object , and you have passed a intent without assigning anything to it.
Your instance cc_Extra isn't doing anything in the activity1. You might wanna pass the "intent" object in your constructor of class like cc_Extras= new Extras(intent); and in the Extras class do the following- Intent intent;
Extras(Intent i)
{
this.intent=i;
}
In the activity2 you are creating the new Instance of Extras(). So according to your code it is going to be NULL by default. If you have done the changes from the previous step, you can create new instance by doing cc_Extras(getIntent());
Corrections in the code
1) In Extras class getExtras() method instead of str=getIntent() use str=intent.getExtras.getString().
2) In the activity2 you are not assigning anything to your String str_Name, so you need to return the string you got in getExtras() method. You can do it by changing the return type to String. Below is the sample code.
public String getExtras()
{
str_Name=intent.getExtras().getString("KEY_Name");
//OR
//str_Name=intent.getStringExtra("KEY_Name");
return str_Name;
}
3) By the doing this you need to catch this string in the activity2 by doing `
if(getIntent() != null && getIntent().getExtras() != null)
{
str_Name=cc_Extras.getExtras();
}`
4) Another thing is you must create intent like this-
Intent intent=new Intent(currentActivityName.this,anotherActivity2.class);
//then use the intent object
EDIT- Your code must look like this in the end...
Act1
public class Act_01 extends Activity {
Extras cc_Extras=null;
Button btn1;
String str_Name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_01);
str_Name = "Buck";
btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//changes to do
Intent intent= new Intent(Act01.this,Act02.class);
cc_Extras= new Extras(intent);
cc_Extras.putExtras(str_Name);
//end
startActivity(intent);
}
});
}
}
Act02
public class Act_02 extends Activity {
Extras cc_Extras;
String str_Name;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_02);
cc_Extras = new Extras(getIntent());
if(getIntent() != null && getIntent().getExtras() != null)
{
str_Name=cc_Extras.getExtras();
}
Toast.makeText(getApplicationContext(), "Name: "+str_Name, Toast.LENGTH_SHORT).show();
}
}
Extras class
public class Extras { //remove "extends Activity" because it is a class not a activity
String str_Name;
Intent intent;
Extras(Intent i)
{
this.intent=i;
}
public void putExtras(String str) {
// TODO Auto-generated method stub
str_Name=str;
intent.putExtra("KEY_Name", str_Name);
}
public String getExtras() {
// TODO Auto-generated method stub
str_Name = intent.getExtras().getString("KEY_Name");
return str_Name;
}
}
Above code will work just on String. You can extend the functionality if you want.
I hope this must work to get your code working!
I'm having problems receiving intent extras between activities.
In my MainActivity I start a Gallery activity to chose video files on external SD card:
public class MainMenu extends Activity {
//Button change video
Button video_change;
//Extra for changing video content
Bundle extras;
//Intent for Gallery view activity
Intent intent;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
intent = new Intent(getApplicationContext(),GalleryView.class);
video_change.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Uri mUri = null;
try {
Field mUriField = VideoView.class.getDeclaredField("mUri");
mUriField.setAccessible(true);
mUri = (Uri) mUriField.get(myVideoView);
} catch(Exception e) {
//TODO: Something here
}
String string = mUri.toString();
intent.putExtra("old_video",string);
startActivity(intent);
}
});
}
#Override
public synchronized void onResume() {
super.onResume();
if (Config.DEBUG)
Log.d(CLASS_NAME, "+ ON RESUME +");
try {
extras = intent.getExtras();
if (extras != null){
Log.d("++ ON RESUME ++","Found Extra!");
String newvideo = extras.getString("new_video");
Log.d("++ ON RESUME ++","NEW VIDEO: "+ newvideo);
Uri tempuri = Uri.parse(newvideo);
myVideoView.setVideoURI(tempuri);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
Then in my GalleryView activity:
public class GalleryView extends Activity {
ImageView back_button;
ListView videolist;
List<String> videos = new ArrayList<String>();
private File[] videoFiles;
//private Cursor videocursor;
//private int video_column_index;
int x=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
back_button = (ImageView) findViewById(R.id.back_button);
videolist = (ListView) findViewById(R.id.listview);
start_listview();
ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.activity_listview,videos);
videolist.setAdapter(adapter);
videolist.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> adapter, View v, int position, long arg3) {
String value = (String)adapter.getItemAtPosition(position);
Log.d("VALUE: ",value);
Intent i = new Intent(getApplicationContext(),MainMenu.class);
// Send the file path
i.putExtra("new_video", value);
startActivity(i);
}
});
back_button.setOnClickListener(new OnClickListener() {
//videolist.setAdapter(new VideoAdapter(getApplicationContext()));
#Override
public void onClick(View v) {
//videolist.setOnItemClickListener(videogridlistener);
Intent intent = new Intent(getApplicationContext(),MainMenu.class);
Bundle extras = getIntent().getExtras();
String newString = extras.getString("old_video");
intent.putExtra("new_video", newString);
startActivity(intent);
}
});
}
public void start_listview() {
String path = ("/storage/extsd/Videos/");
File directory = new File(path);
videoFiles = directory.listFiles();
try {
for (File f : videoFiles) {
Log.d("FILE: ", f.toString());
String file = f.toString();
Uri tempuri = Uri.fromFile(f);
videos.add(file);
}
//Set the visibility of the progress bar to false.
findViewById(R.id.relativelayout_progress).setVisibility(View.GONE);
} catch (Exception e) {
// TODO: handle exception
}
}
}
The problem is, I when I return back to the MainMenu activity, I the extra is found, but is null! From logcat:
MainMenu + ON RESUME +
++ ON RESUME ++ Found Extra!
++ ON RESUME ++ NEWVIDEO: null
Even if I put the extras = intent.getExtras() call in the onCreate, it never gets called because it never passes the extras != null check
HOW I FIXED IT (THANKS TO STEFAN'S ANSWER)
So my MAIN problem was that my Main Activity was always being set to the background whenever I started the new Gallery Activity. My manifest file dictated that it would do a android:launchMode="singleTask" on the Main Activity. So, somehow when the Main Activity was re-started, the intent was never truly passed since the app was always running in the background and never passed the intent extras. So I tried the onNewIntent() method call and tried the piece of code in there to receive the extras, and it worked! Thanks again to Stefan!
What you are doing is to call the MainActivity again after opening the gallery. Depending on the flags used in your manifest, that might cause that your main activity is not launched a second tim, but that your initial main activity is unpaused and raised to foreground.
If this is the case, due to the activity lifecycle, onCreate(...)will not be called again, but you can check if the following method is called:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
//TODO: check here if your intent extras arrive and log, then debug
}
I have three Activities. MainActivity,ActivityB and ActivityC. In activity A and B there are two buttons source and destination in both activities. in Activity C there is a list of data. when button is clicked (either Source or destination) from activity A and B. both Activities are calling Activity C
code for Activity A is following
public class MainActivity extends Activity {
TextView source,destination;
Button sendSource,sendDestination,btnTob;
String src,des,activity,checksrc,checkdes;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
source=(TextView)findViewById(R.id.tv_rcvDataA);
destination=(TextView)findViewById(R.id.tv_rcvDataAa);
sendSource=(Button)findViewById(R.id.btn_sendA);
sendDestination=(Button)findViewById(R.id.btn_sendAa);
btnTob=(Button)findViewById(R.id.btn_toB);
sendSource.setText("source");
sendDestination.setText("destination");
src=sendSource.getText().toString();
des=sendDestination.getText().toString();
activity=getClass().getSimpleName();
sendSource.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent send= new Intent(MainActivity.this,ActivityC.class);
send.putExtra("source",src);
send.putExtra("Activity",activity);
startActivity(send);
}
});
sendDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent senda= new Intent(MainActivity.this,ActivityC.class);
senda.putExtra("destination",des);
senda.putExtra("Activity",activity);
startActivity(senda);
}
});
btnTob.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent movetoB= new Intent(MainActivity.this,ActivityB.class);
startActivity(movetoB);
finish();
}
}); }}
and code for Activity B is
public class ActivityB extends Activity {
TextView sourceB,destinationB;
Button sendSourceB,sendDestinationB;
String src,des,activity,checksrc,checkdes;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);
sourceB=(TextView)findViewById(R.id.tv_rcvDataB);
destinationB=(TextView)findViewById(R.id.tv_rcvDataBa);
sendSourceB=(Button)findViewById(R.id.btn_sendB);
sendDestinationB=(Button)findViewById(R.id.btn_sendDataBa);
activity=getClass().getSimpleName();
sendDestinationB.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent senda= new Intent(ActivityB.this,ActivityC.class);
senda.putExtra("destination",src);
senda.putExtra("Activity",activity);
startActivity(senda);
}
});
sendSourceB.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent send= new Intent(ActivityB.this,ActivityC.class);
send.putExtra("source",src);
send.putExtra("Activity",activity);
startActivity(send);
}
});}}
now how to check in activityC which activity is calling this activity and which buttonclicklistener is calling the intent
You need to send the value for determine what value and what activity via Intent.putExtra(). Please be remember that you need to set the key as the first parameter for Intent.putExtra(), like
intent.putExtra(THIS_IS_THE_KEY, THIS_IS_YOUR_VALUE);
You need to create something like this:
// This is the key for your putExtra
// you need to create this as global variable.
public static final String FROM_KEY = "FROM";
public static final String ACTIVITY_KEY = "ACTIVITY";
public static final boolean IS_FROM_SOURCE = true;
// This is a sample to send data to Activity C
// where the activity caller is B and from source
Intent senda= new Intent(ActivityB.this,ActivityC.class);
senda.putExtra(FROM_KEY, IS_FROM_SOURCE);
senda.putExtra(ACTIVITY_KEY,"activity_a");
Then in your Activity C, you need to receive the Intent Extra.
You can get the value in Activity onCreate(), something like this:
Bundle extras = getIntent().getExtras();
boolean from = extras.getBoolean(FROM_KEY);
String act = extras.getString(ACTIVITY_KEY);
// do something here if from activity a
if(act.equals("activity_a")) {
if(IS_FROM_SOURCE) {
// do something if from source
} else {
// do something if from destination.
}
} else { // if from activity a
if(IS_FROM_SOURCE) {
// do something if from source
} else {
// do something if from destination.
}
}
In onCreate or anytime after that method is called in Activity-C, you should do the following:
Intent intent = getIntent();
if (intent != null) {
String activity = intent.getStringExtra("Activity");
String src = intent.getStringExtra("source");
// Do something with those values
}
I am new to learning Array in android studio. Please show me some examples in details. I have write an example here and I want to display the Array data from MainActivity into second_page activity .
MainActivity.java
public class MainActivity extends AppCompatActivity {
String my_array[]={"dog","cat","tiger"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void next_page(View view){
Intent intent = new Intent(this,second_page.class);
intent.putExtra("my_array_next", my_array);
startActivity(intent);
}
}
second_page.java
public class second_page extends MainActivity {
TextView get_data;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_page);
get_data=(TextView)findViewById(R.id.tv);
Intent intent=getIntent();
// coding here to display the array data
// sth like abc.setText(display_array_data);
}
Please advice. Thank you!
If you are trying to send a String-array from one Activity to another this can be done in the Intent.
In ClassA:
Intent intent = new Intent(this, ClassB);
String[] my_array = new String[]{"dog","cat","tiger"};
intent.putExtra("myArr", my_array);
startActivity(intent);
In ClassB:
public void onCreate() {
Intent intent = getIntent();
String[] myStrings = intent.getStringArrayExtra("myArr");
}
this may helps you
In second_page.java, receive the array you pass via Intent and set it to your TextView like this
#Override
protected void onCreate(Bundle savedInstanceState) {
...
String[] array = intent.getStringArrayExtra("my_array_next");
// TextView display a String so you should convert your Array to String
String str1 = Arrays.toString(array);
get_data.setText(str1);
}
First take the array:
Intent intent = getIntent();
List array;
if (intent.getExtras() != null) {
array= intent.getExtras().getBoolean("my_array_next");
}
Then print
get_data.setText(array.toString());
Sending Class:
Intent intent = new Intent(this, ClassB);
String[] myStrings = new String[] {"test", "test2"};
intent.putExtra("strings", myStrings);
startActivity(intent);
Reciving Class:
public void onCreate() {
Intent intent = getIntent();
String[] myStrings = intent.getStringArrayExtra("strings");
}
In your Second activity:
String[] array=getIntent().getStringArrayExtra("my_array_next");
I think you need to go through basics, go to https://developer.android.com/index.html to get started.