Android :: Difference Between Activity / Application Context?
Nov 8, 2010This has me stumped, I was using this in Android 2.1-r8 SDK: Code...
View 1 RepliesThis has me stumped, I was using this in Android 2.1-r8 SDK: Code...
View 1 RepliesI wanted to know what is the difference between Context.startService(intent) and startService(intent) and does it matter which one is used?
View 1 Replies View RelatedI 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.
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 RelatedI 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?
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.
Can anyone tell me how to access context of a class which is not an activity?
View 10 Replies View Relatedi have dialog style activity android:theme="@android:style/Theme.Dialog"The menu appears about 50 px from the bottom of this dialog. So if activity screen is too small - it right in the middle of the screen. Is there any way to anchor menu to the bottom of the screen?
View 5 Replies View RelatedDoes someone know how to display images in an activity's context menu? I've tried setIcon(resId) and it doesn't work (although it does work in the Options Menu).
View 2 Replies View RelatedI have a need to capture some user input when an activity opens for the first time. I'm hoping to give the user a list of options to select from, which will be pulled in dynamically. I'll then store the selected value locally for future use. I'm not finding a way to do what I'm after and was wondering if anyone has run into this before and how they solved it.
Fantasy Football<http://chriswstewart.com/android-applications/fantasy-football/>- Android app for fantasy football fanatics and MFL owners Social Updater<http://chriswstewart.com/android-applications/social-updater/>- An easy way to send your status blast to multiple social networks
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.
Please find the code sample below:
public class Abc extends Activity implements OnClickListener{
private ListView displayList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlayout);
displayList =(ListView)findViewById(R.id.addressbooklistview);
addressbookAdapter = new CustomListAdapter(this,addressbookList);
displayList.setAdapter(addressbookAdapter);
registerForContextMenu(displayList);}
I am not able to invoke the context menu on long press. Please let me know any solution for the same.
I tried to create a edittextbox, and button next to it, in the status bar.! I created it and tried to launch the browser activity, when somebody enters a URL in the textbox & click that button.
I get runtime exception as below.Can anyone please help what is the issue with this exception ? I know that Status bar is not a seperate activity. It is part of 'PhoneWindow'.
CODE:.............................
I have list activity with custom array adapter and I can't to get context menu when make long press on list item.
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Why I do not see context menu? What I do wrong? How to get context menu with array adapter and ListActivity.
I had come across a code snippet which calls for an activity without referring to any context. Before, i was considering that context is used to tell about the calling component. But as i came see that another component can be called without any reference to context, it makes me wonder what purpose it might be serving. please put some light on it.
Here is the code which calls for an activity without referring to 'context'
CODE:............................
What's the difference between file, class and activity in android?
View 3 Replies View RelatedIn an Android app, is there anything wrong with the following approach..
View 4 Replies View Relatedthe difference between context menu and option menu in android? When I click the menu button on the emulator, is that option menu? or context menu? And how to invoke the other menu (not trigger by the menu button)?
View 2 Replies View RelatedI'm working on an Android application that has several Activities. In it I have a class with several static methods. I would like to be able to call these methods from the different Activities. I'm using the static methods to load data from an xml file via a XmlResourceParser. To create a XmlResourceParser requires a call on the Application Context. So my question is, what is the best way to get a reference to the Application Context into the static methods? Have each Activity get it and pass it in? Store it somehow in a global variable?
View 2 Replies View RelatedHow can get the active context of an application?
View 3 Replies View Related- Hide quoted text -
View 2 Replies View RelatedIs it possible to appear in link for say launching one application in some other applications. Typical example would we on desktop when we right click and get option Open With and see all choices of applications to open with.
View 3 Replies View RelatedCan anyone say me the main difference between intent and pending intent? And their usage in application with example.
View 2 Replies View RelatedI just bought a LG Ally yesterday. What is/are the difference(s) between a widget and an application? I seem to have both a YouTube app and a YouTube widget. Are they different things or will they both do the same tasks.
View 6 Replies View RelatedI recently purchased the new Evo. This is my first smart phone, Droid, etc. Pretty much I am going from the basic to the top. I have read through the forums and I have done all of the tips & tricks for saving your battery. At this time I am basically just using my phone to check email, facebook, twitter, browse the Internet, and as a camera, all of which I could do on my last phone, the Sanyo spc-2700. After all of the rant & rave about this phone I went for it. Can anyone give me tips and tricks that are out there and would make me feel like I got my moneys worth out of the phone? I mean I really love the phone, size, clarity, etc, it's worth it but I feel as though I am really missing the big picture here.
My questions are:
What is the coolest thing about the phone?
What applications should I download and use?
What is the difference between an application & a widget?
Is there any difference between what happens when you use a Task Killer App to kill an app vs. what happens when the Android OS kills an app due to scarce resources? The Android SDK says that the Application.onTerminate() method isn't called when the OS kills an app due to scarce resources. So it sounds like the OS doesn't cleanly close apps and that it does exactly what the much-debated task killers do. If they do the same thing, then task killers don't do any more harm than the OS itself, right?
View 3 Replies View RelatedIs it possible to attach Menu to an application rather than each activity in the application? I have 20-23 activities in my application and it doesn't make sense me to add same menu to all the activities.
View 5 Replies View RelatedHow can I launch a contextmenu from a contextmenu? I'm trying to replicate the MediaPlayer action that happens when you long click a song, then click "Add to playlist" in the resulting contextmenu. When you click that menu item, another contextmenu pops up with "Add to playlist" as the title, and "Current playlist", "New", and however-many-playlists-you-have defined after that.
View 4 Replies View RelatedI have 3 activity in my application. My first activity (Main) has 2 button that starts other activities (One & Two). The One Activity starts a countdown timer on UI. When I click back button Android closes this activity and when I re-open activity, my timer is resetted.
I try also overriding:
CODE:.....
And it's works correctly but when I re-open the Main Activity, Android shows me my timer activity. How can I resolve this problem?
I have an application with several Activities. My A Activity has the Manifest Intent filter parameters: action.MAIN and category.LAUNCHER. after its being loaded I call Activity B and finish() A since I don't use it anymore.
After I run my application, go from Activity A to B and press the Home button, when I relaunch it from the applications menu or from the Market app for ex.(not by a long press on the Home button), it starts from the A Activity and do not save its last Activity B.
I definitely know that this is possible to relaunch an application from its last Activity (some application from the Market do support it) and I think that this can be determined by the Manifest parameters but I don't know which one.
How to implement it so my application can relaunch from its last Activity B?