Android :: Pass Activity Context To Constructors To Use Internally / Is This Bad?

May 26, 2010

Is is bad practice to pass the Context to a constructor and save it as a private variable for internal use? The other option is to pass the Context as a parameter to methods that need it.

Which is the better option?
I have a feeling that passing to the constructor might result in memory leaks accidentally.

Android :: Pass Activity Context to constructors to use internally / is this bad?


Android : Get Context Without Having To Pass It As Argument?

Aug 21, 2010

I'm not sure if this is an Android question or just due to my being new to Java as well. I'd like to use the getString method to get strings from my resources (R.string.whatever). I see that this is a method of the Context class, and I can call it directly from within my main Activity class. But I also have some utility classes in their own class files and can't simply call this method from them. What seems to be required is for me to pass the context (the Activity object) into these other classes via their constructors. Then I can call the method e.g., mCtx.getString(). I guess my main question is whether there's another way to get the Context without having to pass it from class to class as an argument.

View 9 Replies View Related

Android :: Pass Context Into Timer / Safe To Use It?

Jul 17, 2010

I'm using a timer which needs context..
Now i have the following code ...

Is this safe to use , or may i be leaking the context here?
btw. this is in a broadcastreceiver.

View 1 Replies View Related

Android :: How Can I Pass A Context Object To A Thread On Call?

May 12, 2010

I have this code fragment: Code...

View 3 Replies View Related

Android :: How Can We Pass Two String Values Of One Activity To Another Activity

Jun 2, 2010

first.java String[] items={"one","two"}; Bundle map = new Bundle(); map.putStringArray ("link",items); Intent myintent = new Intent(view.getContext(),two.class); myintent. put Extras (map) ;startActivityForResult(myintent,0); second.java Bundle map=this. get Intent() .getExtras(); String links=map.getString("link"); tell me that how can i get the two string values from one activity to another one. such as links[0]="one"; and links[1] ="two";

View 2 Replies View Related

Android :: Context To Use In A Activity Class?

Mar 3, 2010

I have a class defined as

public class viewGroups extends ListActivity

Somewhere in the class I have

objItem = new clsContactGroups(context);

I am wondering what is advised to be used here? Which context?
I know four choices, but maybe there are others...

this
this.getApplicationContext()
this.getBaseContext()
this.getParent()

I use this Context to show a Toast. So I would like to show on the front-most view visible.

View 1 Replies View Related

Android :: Pass Data To New Activity

Aug 24, 2009

I have two activity in my project. I am callilng second activity from main activity. can some one tell me how can i pass some data to that activity? Simply i want to pass object array. Can some one tell me how can i do it ?

View 5 Replies View Related

Android :: Pass Data Through New Activity?

Jun 29, 2010

In my Android app,I start a new activity with startActivityForResult(). I get the result in onActivityResult() perfectly. My problem is that there is a small bit of data that I know before I start the activity and I need that value to be available in onActivityResult(), too. I tried attaching it to my intent as an extra, but it wasn't attached to the intent that is available when the activity returns the result. I made it work by storing the data in a global variable, but I really don't like that approach. Is there a better, right way to pass data through an activity (instead of just to it)?

View 1 Replies View Related

Android :: Possible To Pass Cursor To An Activity?

Oct 16, 2010

Is this possible? I am trying to open a SQLite database cursor in one activity, and pass it to another activity.

View 2 Replies View Related

Android :: How To Pass Handler To Another Activity

Jul 26, 2010

Assume that there activity A and B, A has a handler, now B is activate by A, how can i pass the handler to B? Currently i have a thread receive messages from socket, and dispatch messages to A and B, I think when B is activated, pass handler to B, then the handler can receive message from the thread. But I don't know how to do.

View 3 Replies View Related

Android :: Pass An Object From One Activity To Another?

Aug 28, 2009

I have an activity which implements an OnItemClickListener.code...

However, I need to pass some objects from MyActivity1 to MyActivity2 --

I see there is an Intent.putExtra() for all the basic types, and I even see a Bundle which is a collection of basic types, but how can I pass a generic "Object" to MyActivity2 ?

View 3 Replies View Related

Android : How Can I Pass Values Of One Activity To Another?

May 31, 2010

How can i pass values of one activity to another?

View 3 Replies View Related

Android : How To Pass Object From An Activity To Another

Oct 15, 2009

There is an activity which has an object. This activity(say A) starts another activity(say B). Can B use some object in A?

View 7 Replies View Related

Android : Pass Image To Another Activity?

Aug 23, 2010

I figured out how to pass a String value between activites thanks to this site, however I'm having trouble passing an image. What I'm trying to to is have a user click a button that opens the gallery and allows selecting of a picture. Then I have another button that opens another activity that displays an ImageView. I want to be able to have that ImageView's image be the chosen one from the previous activity.

Here is the class that has the button I'm clicking to open the gallery and retrieve the chosen image: code...

What I'm not sure about is in the OnActivityResult if I should pass the selectedImage or the chosenimage in the b.putExtra("bitmap", selectedimage); line. I tried both but I didn't see an image on the second activity. Also I wasn't sure in the PreviewScreen class if I'm setting the imageview correctly. Any help is appreciated. Thanks.

View 1 Replies View Related

Pass Data From 1st To Third Activity In Android

Dec 21, 2012

This is my 1st activity code:

Intent i = new Intent(getApplicationContext(), CustomerLogin.class);
i.putExtra("GrandTotal", mGrandTotal);
startActivity(i);

This is my 2nd activity code:

Intent in = getIntent();
Bundle b = getIntent().getExtras();
String total = b.getString("GrandTotal");
TextView grandtotal = (TextView) findViewById(R.id.grand_total);
grandtotal.setText("Welcome ," + total );

Here the value is pass from 1st to 2nd activity successfully. Now i have to pass these value to third activity.how can i do.

Now this is my 2nd activity:

if(isUserValidated && isPasswordValidated)
{
Intent intent = new Intent(CustomerLogin.this,PayPalIntegrationActivit y.class);
intent.putExtra("GrandTotal", total);
intent.putExtra("login",username.getText().toStrin g());
startActivity(intent);
}

This is my third activity:

Bundle b = getIntent().getExtras();
String total = b.getString("GrandTotal");
TextView grandtotal = (TextView) findViewById(R.id.check);
grandtotal.setText("Welcome ," + total );

Now i have to run the app means am getting the total value on 2nd activity.but am not getting the total value in 3rd activity.

This is my full source code:

1st activity:#5564017 - Pastie

2nd activity:#5564018 - Pastie

3rd activity:#5564020 - Pastie

View 2 Replies View Related

Android :: Get Activity Object While In View Context

Oct 10, 2010

This is a followup to this post: http://stackoverflow.com/questions/3897176/findviewbyid-in-a-subclassed-surfaceview-throwing-runtimeexception Based on Romain Guy's feedback (which I'll accept shortly as it is a solution), I'd like to obtain the calling Activity from within the View, so that I can use it to obtain the desired Text View resource. I don't see any methods in View that return Activity. What is the proper way to do this? Or is there a better alternative for working with TextViews from within another View context. Basically, I am calling setContentView(R.layout.xxx) in onCreate() (as usual), so I don't really have a way to pass in references to additional TextViews unless I awkwardly retrieve the View after setContentView and then make calls on it.

View 1 Replies View Related

Android :: Difference Between Activity / Application Context?

Nov 8, 2010

This has me stumped, I was using this in Android 2.1-r8 SDK: Code...

View 1 Replies View Related

Android :: Calling StartActivity From Outside Of An Activity Context

Oct 12, 2010

I have implemented a ListView in my Android application.

I bind to this ListView using a custom subclass of the ArrayAdapter class. Inside the overridden ArrayAdapter.getView(...) method, I assign an OnClickListener. In the onClick(View v) method of the OnClickListener, I want to launch a new activity.

I get the exception:

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

How can I get the context that the ListView (the current Activity) is working under?

View 2 Replies View Related

Android :: Start An Activity From A Non-context Class?

May 4, 2010

For example, I have an activity that uses a utility class. I would like to be able to start an activity from the utility class and have the activity result sent back to the utility class.

The only way I could think of starting the activity was to pass the original activity to the utility class, so that the utility class could use the original activity to start the activity. The problem with this is that the activity is sent to the original activity, rather than the utility class.

I also thought of actually making the utility class an activity itself, but that would make using the utility class much more complicated.

View 10 Replies View Related

Android : Access Context Of A Class Which Is Not An Activity?

Jan 28, 2009

Can anyone tell me how to access context of a class which is not an activity?

View 10 Replies View Related

Android :: How To Set / Pass Values From One Screen (activity) To Another?

Sep 30, 2010

How do you set/pass values from one screen (activity) to another? What I have in the R.layout.main view labeled Calculator contains the code for doing calculations. The main.xml contains the layout (view) of the main screen. I have created an options menu which has another screen which shows you setup (R.layout.setup). The dialogsetup.xml contains the layout (view) for it.

When you press the menu button, you get the options menu. If you select "Setup", then it will display the setup screen. Now what I need to do is take the values from the setup screen (radio button and text values) and place them in the main screen so that when you exit the setup screen and go back to the main screen, you can take those values and use them in your main code.

View 12 Replies View Related

Android :: Trying To Pass Data From Notification To Activity

Oct 30, 2010

I'm trying to pass data from notification to activity.

View 1 Replies View Related

Android :: Pass Data From Thread Into Activity

Jun 12, 2010

I am want to pass data back from a Thread to Activity (which created the thread). So I am doing like described on Android documentation.Only one thing I am missing here - where and how should be defined mResults so I could access it from both Activity and Thread, and also would be able to modify as needed? If I define it as final in MyActivity, I can't change it anymore in Thread - as it is shown in example.

View 1 Replies View Related

Android :: Pass Data To A Child Activity

Nov 2, 2010

I wounder if there is some possible to know from which parent Iam coming from in the child so I can do different stuff depending on who the parent is of the activity.This is how Iam going over to the child. But I don't know how to handle this in the child to check who is the parent. The above code is used on one of the parents,, is there somehow I can use "EQ_CODE_SELECT_LOCATION"? Also I wounder how is possible to send data to a child activity?

View 1 Replies View Related

Android :: Way To Pass Bundle To Activity Set As Singletask?

Apr 22, 2010

So I have a MapActivity that runs an asynchtask that occasionally updates what exactly it's displaying on the map (via a string). I originally pass this string in from the intent when the activity is first created. And then if you click on one of the drawables on the map, it opens a new activity, which can then create a new mapview (same class) with a different string setting. The problem I have is that I only want one instance of the mapview to be running at once. Thus I set android:launchmode="singletask" in the manifest. This works in that it brings the mapactivity to the front, but is there any way to send it a new intent bundle to get a new setting for the string it needs? I tried regetting the extras from the bundle, but it seems to retain the old bundle, not the new intent that was passed to it. I'm not sure I want to do startActivityForResult because the 2nd activity may or may not want to update the original activity. I hope that made sense. I can post code if necessary, but I think that should explain my situation.

View 2 Replies View Related

Android :: How To Pass String From Activity To Service?

Aug 30, 2010

On Sat, Aug 28, 2010 at 3:53 AM, Ravi Grandhi <grk.r...@gmail.com> wrote: > How to pass a String from an activity to a service?

View 2 Replies View Related

Android :: Pass Database Results Into New Activity?

Oct 4, 2009

I'm working on an app, and one activity has a worker thread that initiates a database query, and if there are results once it has returned I would like to send these results to a new activity that will display them. Unfortunately I don't see a way to pack the Cursor object into the Intent object that I am using to start the new activity. When I was doing Windows Mobile development in the past all I would do is edit the constructor for the window to pass in the data, I've searched around but I can't find a similar solution for Android. What is the best way to pass my database results into the new activity?

View 3 Replies View Related

Android :: Pass List<GeoPoint> To Another Activity?

Nov 10, 2010

I have an ArrayList of type GeoPoint.

private List<GeoPoint> points = new ArrayList<GeoPoint>();

I want to pass points to another Activity and retrieve the data in that activity. How do I do it? I know I have to use the parcelable but I searched, but could not find a way to pass ArrayLists.

View 1 Replies View Related

Android :: Example Code To Pass Value From New Activity To Old In Droid?

Aug 26, 2010

I am using two Activity as Old Activity and New Activity,i want to pass some value from New Activity to Old Activity.how can i pass the value from New Activity to Old Activity. please give some example code for that.

View 2 Replies View Related

Android :: Pass String From Activity To Layout?

Aug 19, 2010

How can I pass a string from an activity to a layout?
I can pass arrays from an activity to a layout with the following activity code...

Is there a simpler way to just pass a single string instead of any array of strings, from an activity to a layout?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved