Passing String array between two class in android application
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[] myStrings = new String[] {"test", "test2"};
intent.putExtra("strings", myStrings);
startActivity(intent);
In ClassB:
public void onCreate() {
Intent intent = getIntent();
String[] myStrings = intent.getStringArrayExtra("strings");
}
Passing string array between android activities
Bundle b=new Bundle();
b.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(b);
Hope this will help you.
In order to read:
Bundle b=this.getIntent().getExtras();
String[] array=b.getStringArray(key);
Passing a String Array Between Java Classes Android App
You're creating a new accelerometer class, which is completely uninitialized since there is no constructor, then you access its member. Of course it'll be null.
Not sure how your two classes are related, but if the activity is called by the service, then you need to pass the string through the intent (through an extra, for example).
Side note: Class names should always start with a capital letter. Method/variable names should have camel case, i.e. "updateArray". Also, you can format your code here by selecting it and pressing CTRL+K.
Passing string array to another activity
You have to do the following:
Intent i = new Intent("Activity")
i.putExtra(key, ArrayName)
Intent i = getIntent();
String[] array = i.getExtras().getString(keyname);
and that's it.
Android - Passing an Array of Classes Between Activities
Since we're dealing with a Map, you should go with:
Object[] array = (Object[]) extras.get("classes"); // you cannot cast to Class[] !
and then:
Class a = (Class) array[0]; // and etc.
Android: Passing String Array over Multiple Activities
You put the code below in a file named data, in your code you then use just it by calling data.array
public class data {
public String[] array = new String[1];
}
But going with just passing through a String[] you shouldn't need bundle.
simply
intent.putExtra("stringArray".String[]);
and get it with
this.getIntent().getStringArrayExtra("stringArray")
pass array between 2 activity with intent
Best solution I can suggest is define your array as
public static int[] xyz=new int[]{1,2,3,4};
And now that static int array can be called or used from any activity provided if they are in the same package.
Here for your example in GraphCurrentActivity,
Add this import statement:
import static yourpackagename.BluetoothLeService.xyz;
//And these lines to read that array:
int[] arraydata;
arraydata = xyz;
And let me know if this was wrong.
Java, trying to pass string array from one class to another
Beside other answers, if you want to pass data from Fragment's "likeTitles" variable to Activity's myStringArr variable on constructor method, you have to do like this:
class MyFragment extends Fragment{
public String likeTitles[] = {"mazda","whynot","OHYEAAAaa","ok","1983198312893"};
public MainFragment(String[] s1){
for(int i = 0; i < likeTitles.length; i++)
s1[i] = likeTitles[i];
}
}
Related Topics
Fragments in Android 2.2.1, 2.3, 2.0. Is This Possible
Preferenceactivity Android 4.0 and Earlier
Navigationview and Custom Layout
How to Filter Android Logcat by Application
Set Span for Items in Gridlayoutmanager Using Spansizelookup
How to Add APKs in an Aosp Build
Adb Install Fails with Install_Failed_Test_Only
Write Android Logcat Data to a File
Programmatically Change Input Type of the Edittext from Password to Normal & Vice Versa
Returning from an Activity Using Navigateupfromsametask()
Android, Make an Image at a Url Equal to Imageview's Image
Custom Cut/Copy Action Bar for Edittext That Shows Text Selection Handles
Android: Getting "Manifest Merger Failed" Error After Updating to a New Version of Gradle
Gradle Build Fails on Lint Task