Android :: Passing An Array In Intent Android
Aug 30, 2010
I've always been under the assumption that you can't pass arrays between activities with extras. But I was just going through the Bundle class docs and saw putStringArray(String key, String[] value) and public String[] getStringArray (String key). Are these new? They both say since API lvl 1, but I don't remember being able to pass arrays.
View 1 Replies
Apr 8, 2010
My background is in C, but I'm relatively new to Java and to Android. I have a question as to whether I'm implementing code in the best way:
As a learning exercise in Java and in meeting the Model-View- Controller pattern, I wrote a simple game. It plays out on a 2D grid owned by the game class, and is drawn to the display by an extended View class. I have it working, but I'm wondering after the fact if I'm going about it the right way.
Here's a simplified version of what I have:
CODE:.................
View 2 Replies
View Related
Apr 1, 2009
I need to pass a 2 dimensional array to an ACTIVITY from a SERVICE. How can I achieve this in minimum number of statements (as in avoiding putExtras for each and every string stored in the array)?
View 4 Replies
View Related
Oct 27, 2010
I have passed one multi-dimensional array to another activity using putSerializable() and retrieve using getSerializable. But I got some problems.
First activity
CODE:.................
Second Activity
CODE:.................
When I am running my application, my application is suddenly stopped. Is this the right method to retrive the String array?
View 2 Replies
View Related
Apr 7, 2009
I am developing an image applications.
One activity decoding image file (jpg, bmp, and so on) to byte buffer RGB 565 or 888 type.
Then want to pass image buffer to another activity for change image data.
I have 3 activity the main decoding activity[A] and selecting effect activity[B] and apply effect activity[C] for change image data.
If i use intent then activity[A] should make intent[1] and putExtra to that intent. and then [B] call getIntent and getByteArrayExtra for get byte buffer.
If user select effect then [B] make new intent[2] and putExtra to intent[2]. and startActivityForResult with intent[2] and activity[C].
Then activity[C] call getIntent to get intent[2] and getByteArrayExtra for get byte buffer again.
There takes much times to make new byte buffer and copy from parent's activity's byte buffer 2 times. [A]->[B] and [B]->[C]
That process drops application performance.
Questions
1. Can i pass intent[1] to activity[C] without make new intent[2] and putExtra byte buffer? by modify intent[1]. (if it works just 1 buffer copy will perform)
2. Can i use application global memory for share byte buffer? if i use hash map how can each activity access same hash map? (if it works don't need to copy buffer)
View 2 Replies
View Related
Jul 23, 2010
I have two activities:
"a" that spawns thread for generating a dynamic array of values inside public void run() function.
"b", graphics activity that will help me draw rectangular pulses based on array values calculated in activity "a" (calculated in a's thread to be precise).
When I am in thread inside "a", how do I pass values of array to activity "b" and
call activity as well.
activity A
CODE:..........
activity B
CODE:..............
View 1 Replies
View Related
Nov 30, 2009
Here is my Problem :
I want to pass multi dimensional String array between two activities or pages.
I already tried with bundle.putextra like methods. But those allow only one dimensional string array.
I really hope you can help me with example java code on this . Here is my String array, final String[][] arr2={{"1","pavan"},{"2","kumar"}, {"3","kora"}};
View 4 Replies
View Related
Oct 14, 2010
I have four groups in a listview each with four url's I want to load in a webView. When the user select a url to goto I set a value like so;
if (position == 0) webb = webb +2;
{
Intent intent = new Intent(this, official.class);
startActivity(intent);
}
I then carryout the intent to move to the webView class where I have given each URL a value like so;
if (webb == 2) mWebView.loadUrl("http://yahoo.com");
if (webb == 3) mWebView.loadUrl("http://www.bbc.co.uk");
But the screen stays blank, if I state the value inside the official.class it works. How can I get this value to pass to another class based on the selection the user makes from the listview.
View 3 Replies
View Related
Oct 16, 2010
I have been trying to get "getExtra" to work but without success, I have a listview with 4 choices which launch a webpage within a webView class, when the user selects the option lets say option 3 I want to pass the value of 3 to the webView class so that it will load the correct webpage, at the moment I get no errors, but the app force closes when I select the option, could this be due to having to announce this in the manifest? can somebody help with where I am going wrong. This is my intent
public void onListItemClick(ListView l, View v, int position, long id) {
if (position == 0) {
Intent intent = new Intent(this, official.class);
intent.putExtra("weburl", 3);
startActivity(intent);}
This is the official class:
public class official extends Activity {
int number = getIntent().getIntExtra("weburl", 0);
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
} return super.onKeyDown(keyCode, event);
} WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browser1);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
if (number == 2) mWebView.loadUrl("http://bcafc.livewwware.co.uk");
if (number == 3) mWebView.loadUrl("http://www.bbc.co.uk");
mWebView.setWebViewClient(new HelloWebViewClient());
View 1 Replies
View Related
Sep 22, 2009
I am creating a database driven app for managing people. I am showing a list of people with each name in a TextView. When a TextView is clicked, I launch a new intent to show the detail for the person. My question: What's the best practices for passing the id of the person to the new intent? The TextView is displaying the name of the person, so how do I know the id of the person? Once I know the id, I know how to pass it to the new intent, but I don't know what the best way to associate the id of the person to the TextView. Is there a best practice for this?
View 2 Replies
View Related
Jun 28, 2010
I would like to create some home screen app widgets that are entry points into an application. I can put a button in the app widget that uses setOnClickPendingIntent to start the activity. The problem occurs when I want to have two of these app widgets that are entry points to different parts of the activity. I need to be able to pass data into the activity that will distinguish these. Since both app widgets use a Pending Intent that starts the same activity, the two Pending Intents are shared and I can't reliably set extras for the corresponding intents.
View 2 Replies
View Related
Jan 14, 2010
I have an application, which sets an alarm using AlarmManager, which starts another Activity when it goes off. The AlarmManager takes a PendingIntent and spawns a BroadcastReceiver class when the specified time comes. I'm wondering whether there is any way that I can pass arguments to this BroadcastReceiver through the Intent object which goes into PendingIntent?I'd like to be able to retrieve arg1 in the BroadcastReceiver's onReceive(Context, Intent) method. I figured that the local variable my_intent would be the second parameter passed on to onReceive by the PendingIntent, but apparently that's not quite right. Is it possible to pass parameters between an Activity and a BroadcastReceiver in this fashion (using Intent.putExtra()) or should I use a ContentProvider instead?
View 3 Replies
View Related
Oct 5, 2010
I would like to pass a considerable sized amount of data (~1500 bytes) between two applications in Android where performance and resource allocation is a priority. The data is basically key-value pairs. The rate at which it needs to be passed from one application to another can vary from a trickle to ~50 packets within a second. I figure I can either:
Wrap all the data inside a bundle, and pass the bundle via an Intent from one application to another. I worry about the performance implications of allocating and de-allocating all that memory to store the bundles.
Write all the data to a SQLite database and provide it to the other application via a content provider. Here I worry about the performance implications of writing all that data to disk, and then having to read it back from disk when it is requested. So, which is the lesser of two evils?
View 1 Replies
View Related
Aug 3, 2010
I have a program that sends a broadcast Intent that needs an "extra" value.The value is declared as being of type Object[], though I know that the elements are always of type Integer or String.That's part of an API not under my control. What's the most concise and/or efficient way to do the equivalent of the putExtra call below?
View 6 Replies
View Related
Aug 3, 2010
Is there a way to convert JSON Array to normal Java Array for android ListView data binding?
View 2 Replies
View Related
Jan 12, 2010
I have Picture data in byte rgb_565 array, and I want convert it in a productive way into argb array. Right now I have found only one (little slow) way to do this: Bitmap mPhotoPicture = BitmapFactory.decodeByteArray(imageData, 0 , imageData.length);
where imageData is my byte[] array in rgb_565, and then: int pixels[] = new int[CameraView.PICTURE_HEIGHT*CameraView.PICTURE_WIDTH]; mPhotoPicture.getPixels(pixels, 0,PICTURE_WIDTH, 0, 0, PICTURE_WIDTH, PICTURE_HEIGHT);
The point is I believe creating a Bitmap object is exacting and not necessary in this case. Is there any other faster way to convert rgb_565 array into argb array? I need this because making image processing on rgb_565 array seems to be a little annoying. Or maybe it is not so hard?
View 1 Replies
View Related
Feb 16, 2010
I am trying to make an application that would be able to send the user's voice over the network using RTP. I am using the ported stack from hsc (JLIBRTP) and I am able to record user's voice in a saperate thread. the problem is that jlibrtp uses has a class named RTPSession that is responsible for the session and has the sendData method that takes a byte [] as argument and the AudioFormat class I am using to record user's voice is in AudioFormat.ENCODING_PCM_16BIT wich is short. I have tried using 8bit audioformat but I get an illigalargument exception in my htc magic and in my emulator. So is there any way I can convert the short [] to byte [] ? would that be acceptable in order of voice quality?, is the above error a known bug for htc magic or the platform doesn't support 8bit audio format?
View 3 Replies
View Related
Oct 12, 2010
I'm new to android developing but right now I'm working on an application that displays Random Facts. Since I don't want it to be in a random order, I would like to have them in a list. I would like to order through them one by one and show them using TextView.
Resources res = getResources();
myString = res.getStringArray(R.array.FactsArray);
That's what I have so far. If I'm right, that just establishes the array so I can be able to use it later. What I had before was rgenerator which chose a random string from the array and displayed it when I clicked a button.
CODE:................
But Like I said, I would like to just order through them one by one when a button is clicked.
View 1 Replies
View Related
Jul 27, 2010
Is there a simple way to convert a JsonArray to a standard Java Array? Obviously, you can iterate and do it explicitly, but I wanted to see if there was a direct way to do so.
View 2 Replies
View Related
Sep 13, 2010
In my android application i need to insert an array into an array and access its values. Is there any way that i can get this done.
View 3 Replies
View Related
Mar 31, 2009
I just want to read <string-array> resource elements into a String array. I don't want to make a view or anything and mess with adapters - just want to transfer the elements. Is there a built in class for this? Or do I need to treat the resource file as a regular file?
View 3 Replies
View Related
Nov 12, 2010
Is there a way to pass an Array List of objects between activities? The myObject implements Parcelable and I'm able to successfully pass the objects around individually, but that means I need to have an exact amount of "myObjects" coded. I want this to dynamically grow/shrink by what the user does with the app. I have seen some posts on the web about doing:
Activity A
ArrayList<myObject> myObjArray = new ArrayList<myObject>();
Then when passing this into the intent I would use:
intent.putParcelableArrayListExtra("myObjArray", myObjArray);
Activity B
ArrayList<myObject> myObjArray = new ArrayList<myObject>();
Bundle extras = getIntent().getExtras(); myObjArray = extras.getParcelableArray("myObjArray");
However, the myObjArray always gets filled with "null". How can I achieve this?
View 3 Replies
View Related
Apr 7, 2009
I have an ArrayList<MyList> aList in an activity. I would like to send this data to another activty. Such that,
ArrayList<MyList> aList;
Intent intent = new Intent(); intent.setClass(mainactivity.this, newActivity.class); intent.putExtra("MyList", aList ); startActivity(intent);
On the receiving activity,
Intent i = getIntent(); newList = (ArrayList<MyList>) i.getSerializableExtra("MyList");
But this gets me no where. ERROR! My intention is to share this List between activities.
View 4 Replies
View Related
Nov 17, 2010
I have searched and searched and I just can't get this code to work. I have a main.xml layout and a setting.xml. I have some values I would like the Settings.class to change in my main apps class.Three string to be exact. I have tried this simple test code in my main app class.
settings.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), Settings.class);
startActivityForResult(intent, 0);}});
//Then a function
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
String value = extras.getString("myKey");
if(value!=null){
Log.d("hmmm",value);}}}
In my settings.class I have the following
returnHome.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("myKey", "YEAH");
setResult(RESULT_OK, intent);
finish();}});
Back in main app class it is not getting logged. Like I said I have three string in the main class that I want settings class to change and send back.
View 2 Replies
View Related
Feb 11, 2010
I have an app which makes use of several layout-views. Every layout - view also got a class for it, which extend the Activity class. One class for example retrieves some database values whilst offering a search form to the user. Afterwards the user can select one of those values and he gets presented with another screen which gives similar options as the one selected. Anyways, I'd like for the first Activity to be able to send an array with data (Strings for example) to the second one. Right now I show an activity by using:
Intent i = new Intent(this, activitysName.class); startActivity(i);
I have no idea whilst using this construction how I can "initialize" the new object with the String array I want to pass to it. So how should this be achieved ? Should I be using something else instead of an Intent-Activity combination ?
View 5 Replies
View Related
Nov 4, 2010
How to pass parameter value to web service in Android?
View 2 Replies
View Related
Jun 7, 2010
I have a Bitmap image and i want to forward the bitmap to another activity. I have two activities Activity A and Activity B. This is how I started the Activity B
startActivityForResult(new Intent(Activity A.this, Activity B.class), 120);
in activity B
private void forwardImage(Bitmap bit) {
Intent i = new Intent(MMS.this, Compose.class);
i.putExtra("MMS", bit);
setResult(RESULT_OK, i);
finish(); }
This is not forwarding to Activity A but if I put a String to the intent it'll forward. This is how I listen to result in Activity A
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
// super.onActivityResult(requestCode, resultCode, data);
switch (resultCode)
case RESULT_OK: Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("MMS");
mmsImage.setImageBitmap(bitmap);
default: break;
} }
How can I pass a bitmap.
View 3 Replies
View Related
Nov 15, 2010
I am working to set a countdown timer. I have successfully (borrowed) a number picker (spinner) and set up the dialog box for the user to set the time. This is in a class called timepickactivity and the variables are hour and mins (R.id.hour and R.id.mins). I want to call the set values (R.id.hour and R.id.mins) from the dialog (timepickeractivity) to the actual countdown class (countdown) but I can't figure out how to get the values.
View 4 Replies
View Related
Mar 2, 2009
I'm programming an Activity that launches a second one through startActivity just like in the Forwarding example. The main difference is that I'd like to pass some data to the second Activity when starting it, for example an item selected in a list owned by the first Activity. I can't find how to do that. Am I missing something? I guess I do.
View 3 Replies
View Related
Aug 9, 2009
I've read the android AIDL documentation and have a general idea of how RPC works between an Activity and a Service. However, for my application it seems overboard to implement such features: basically, I want to pass a Service a nice handler so its thread can pass data to my Activity. Currently I'm getting around this by using a static public member (a hack) but I would prefer just passing a Handler object in the Service's starting Intent. However since a Handler isn't serialize-able , I haven't found a way to pass it to the service without a simple static member hack. Any insight? Or, am I just going to have to suck it up and do a formal RPC to the service?
View 1 Replies
View Related