Android :: Get Information Of Activity Lifecycle Callbacks In Views Drawn?
Aug 3, 2010
I want to get the size of a view that is in my activity but I am not able to get that information in any of the activity lifecycle callbacks (onCreate, onStart, onResume). I'm assuming this is because the views have not been drawn yet. At what point are views drawn and is there a callback I can put my code so I can get the size of the view?
View 2 Replies
Oct 16, 2010
I need to capture the absolute positions of some ImageViews to use as drop targets. I can't seem to find what event I need to put my code in to read the screen and get the Left(), Top() .. positions. I do not want monitor the inflation of each individual view. There must be some sort of onScreenFinsihed type of event, but I can't find it. onMeasure and onDraw seem to fire at the start of their work, I need to know when they are done.
View 1 Replies
View Related
Aug 21, 2010
I am new to android programming, but I am trying to learn. I have written some code that takes in some parameters through a "normal" view with checkboxes and textviews. Then I use this information to generate a lot of numbers that I want to display in a listview. I have managed to create a listview when I press a run button, but how do I pass the information from the main view to the listview. Is it best to pass the information one number at the time or a large array with all the numbers. The list of numbers can be really large.
View 2 Replies
View Related
Oct 5, 2010
In the Android Application Fundamentals it says that after the call to the onStart()-method of the activity lifecycle either the callback method Resume() or onStop() is called. In case of an "normal" Start of an activity the system calls onCreate(), onStart(), onResume().But does somebody know an example where onStart() - onStop() are executed one after another?
View 2 Replies
View Related
Jul 14, 2009
I just ran into a situation where it looks like a static variable reference is persisted across activity sessions. I didn't expect that because I thought that when an activity exits, it's de-referenced and garbage collected. I am wondering if anyone can shed some (more) light on when the VM eliminates object references for Activities and Services and in particular when static variables get reset to default values?
View 7 Replies
View Related
Aug 7, 2009
http://developer.android.com/reference/android/app/Activity.html
The Activity Lifecycle could have implementation and or design bug: One case is to initialize a big image in onCreate(), try to reuse the image during the whole lifecycle, and then recycle the image in onDestroy(). Test showed that onCreate() is called every time one navigate away from the activity and back again, but onDestroy() is not called at all. This behavour causes memory leaking for the big image (size 960*1920). After 6+ times away and back to activity, the system runs out of memory and has to kill the process.
One workaround is to initialize the big image in onResume() and recycle in onPause(), but that's not so good reuse.
Could it be better to change the process (as shown in the diagram) a little bit such as: Call onDestroy() first when a process is killed?
View 3 Replies
View Related
Mar 4, 2010
I have a problem with the activity lifecycle specifically on Nexus One (2.1 running on emulator works fine). If I just create a simple empty Activity with no special launchModes that logs the calls on the onStart and onStop methods, this is what I see: - launch app: onStart called; - home button: onStop NOT called; - launch app: onStart NOT called; - home button: onStop NOT called: and so on. Sometimes if I press the back button then the onStop is not called, but the when i launch the activity again the onStart is called and right after the onStop is called. Similar results with different launchModes. What is going on? Can anyone confirm this?
i found an android issue for the problem here: http://code.google.com/p/android/issues/detail?id=6094 and a similar thread here http://groups.google.com/group/android-developers/browse_thread/threa.
View 24 Replies
View Related
Jul 12, 2010
I have a custom view on which I need to call a method from my activity after the view has been measured in onMeasure. I would like to know exactly when onMeasure is called in the View layout process. It looks like onMeasure is called after my activity´s onCreate, onStart, and onResume. I could override onMeasure and maintain a variable that contains whether the view has been measured or not. However it would be nice to know if there is a rule that relates onMeasure to the activity lifecycle?
View 4 Replies
View Related
Sep 15, 2010
I'm binding to a local Service (that is, not using IPC and AIDL) from several activities. I want to ensure that I'm not holding references to this service from activities that the user isn't using. My options are: 1.) to bind to the service in onCreate() and unbind in onDestroy(). 2.) bind in onStart() and unbind in onStop(). 3.) bind in onResume() and unbind in `onPause(). Or some combination of these. Which is the best-practice way of binding and unbinding to a local service? Do I not need to be concerned with holding local connections from stopped activities? Additionally, once bound to this particular service I am retrieving a Cursor which is attached to my ListActivity via a CursorAdapter. The data retrieved by the Cursor may have changed while the Activity was out of view so I want to requery it when the Activity is shown again. If I bind in onCreate() I can requery in onRestart(). If I bind in onResume() each time the data will be fresh because I'll query it in the Service's connected callback.
View 1 Replies
View Related
Oct 4, 2010
I'm having a couple of problems with an alarm app I am developing.
The first thing that I think is a bit weird is that when an alarm goes of and wakes the phone up. These things happend.
oncreate
onresume
onpause
onresume
Why are they run in that order? The last two should not be called? And this is what's causes me big trouble, because when i press home or back on the phone, onPause is run, which I want to call finish() from. And that part works as it should, but that does not work when the phone wakes upp from sleep bacause of the onPause call...
View 2 Replies
View Related
Jun 29, 2010
My app keeps force closing before it starts, eclipse returns no errors in my code and my xml is good.
package com.mhe.test.scan;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class main extends Activity {
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button myScanButton = (Button) findViewById(R.id.myScanButton); myScanButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
} } );
} EditText totalbox = (EditText) findViewById(R.id.totalbox);
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) { if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
// Handle successful scan totalbox.setText(contents)
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel totalbox.setText("@string/bummer");
} } } }
Essentially it is supposed to call zxing Barcode Scanner to scan a barcode on a button click and return the result into an EditText field.
View 2 Replies
View Related
Jan 25, 2010
Is there any way to query a root view of an activity for all of its child views even before the root view or its children have been inflated? I guess what I'm looking for is whether a view knows ahead of time what children it will have before it gets inflated, and can I get that list in some way. Bizarre I realize, but I think it will help me with some unconventional automation testing I'm working on. I haven't found anything in the API like this.
View 1 Replies
View Related
Nov 26, 2009
My app is made of two activities, A and B. I'm considering this sequence of steps: Activity A is started. A launches B [A is paused, B is running]. B launches a map intent [A and B are both paused now]. Now the user is using the maps application and the system decides it needs more memory. Can the system kill only one of my activities for memory, or will it always kill all activities in a "process" in this situation?
Both activities share some static data like:
class Data {
public static String mName;
public void save() {
// write to file: mName;...................
View 1 Replies
View Related
Oct 26, 2012
I'm writing an application for Android and have multiple Activities, there are three to be exact. When a user drills down to the record they would like to view, they can modify it.
The issues is that when I click the back button to move to the previous screen, i'd like to refresh it to reflect the update performed by the end user. I can't figure out how to hook onto the appropriate event and then refresh my data on that view.
View 3 Replies
View Related
Oct 19, 2010
am not too experienced in android and i am just using the TabActivity, so please bear with me. i keep seeing post about not using activites in Tabhost but views. and am not sure which is which and if thats the reason of my latest headache? i have a code with 4 tabs like this:
// Category TabActivity class
tab.setContent(new Intent(this, Mylist.class));
tab1.setContent(new Intent(this, Mylist.class));
tab2.setContent(new Intent(this, Mylist.class));
and each tab is showing the result of a method in the Mylist Activity.is that using an activity in a tab or displaying a view? whats the difference?.i have a context menu on an item selected in the Mylist Activity which updates the list. how can i reflect the changes in the list back to the tab in other to display that particular method in the Mylist class, that was set as the tabs content. obviously this will change if i updated or deleted an item from the list when the tab is shown. i think its possible with onResume(), but don't know what to call there or is there any better way?in the Mylist class, i have tried this little piece of code to restart the TabActivity:myAdapter.deleteItem(id);
fillData(); //
Intent refereshCategory = new Intent(this, Category.class);
startActivity(refereshCategory);
its restarting the activity after the item have been deleted, but how can i only show the tab whose view was in focus when it restarts and i don't want fillData() method to be shown as it does not have to do with the tabs. i hope i made myself clear enough
View 1 Replies
View Related
Jun 14, 2010
I'm interested in android activity lifecycle and I would like to get more detailed description/documentation/reference than widely available basic (onCreate->onStart->onResume) one.
My need comes from realizing that starting new activity (Theme.Dialog styled) from onAttachedToWindow() greatly improves response time if comparing to starting it from onCreate(). I wonder how this onAttachedToWindow() fits into whole android activity lifecycle. Official API ref description "Called when the window has been attached to the window manager" doesn't help a lot.
View 1 Replies
View Related
Feb 16, 2009
I have been practicing with android for a while and read a few books but there is something I can not find anywhere even on the net. I am interesting in the activity manager and how it works. Especially how the activities are pushed on the stack then pulled, etc... I looked everywhere I could for such documents but the only things I could find were overall documents with not much details. I have downloaded the entire source code (cupcake branch) and started to have a look at it but obviously the code is big and very complicated. I was just wondering if an android google engineer somewhere or even somebody else who could let me know where I could find such information (whether it is a document, a link, etc...).
View 2 Replies
View Related
Jul 13, 2009
I have the instance to my activity, and I want to get all the views that are in this activity. I need to add a listener to each view, for any activity. That means I can't user findViewById. Is there any way to do this? I was hoping for a activity.getViews() or something, but it doesn't exist.
View 4 Replies
View Related
Jul 10, 2010
Is there a way to get every view that is inside my activity? I have over 200 views including buttons, and images, so i want to be able to access them by using a loop.
View 1 Replies
View Related
Aug 6, 2009
i have created some xml layout: 1- toplayout.xml 2- botlayout.cml 3- middlelayout.xml now i can only set one view as in setContentView(R.layout.toplayout); please advise how can i show all three views in my activity?
View 2 Replies
View Related
Feb 10, 2010
I simply want to create a ListView above this webview (covering it up...but sitll allowing the webview to run). I could toggle the views on and off.
View 2 Replies
View Related
Mar 18, 2010
I am trying to create a simple Android application that has a ActivityList of information, when the application starts, I plan to start a Service that will be constantly calculating the data (it will be changing) and I want the ActivityList to be in sync with the data that the service is calculating for the life of the app. How can I set up my Activity to be listening to the Service? Is this the best way to approach this problem? For example, if you imagine a list of stock prices - the data would be being changed regularly and need to be in sync with the (in my case) Service that is calculating/fetching the data constantly.
View 3 Replies
View Related
Nov 6, 2010
I'm new to Android, and event driven code in general. Rather than embed loads of anonymous event listener classes in my Activity to handle onClick events etc, I defined separate classes to keep the code clean. Then I use them e.g. like this
myButton.setOnClickListener(new MyEventListener());
So, when 'myButton' gets clicked, MyEventListener's onClick method does some stuff.
I wanted to know the best practice for
a) accessing things in my Activity from the event listener. For example to change the text of a label. The onClick event takes a View in, but this is the view for the button that's been clicked, so if the label is NOT a child of my button, I can't use findViewById to get a handle to it. I've modified the constructor to pass in a reference to the label, so that the event has a handle to it but not sure if this is the most elegant way of doing it.
b) Passing information back e.g. when my event fires, I might want to disable some EditText fields. I'm thinking the proper way to do this is probably to dispatch another event from my event listener, that the Activity listens for, and when it sees the event, disables the fields in question. Is that the way to do it in Android?
View 1 Replies
View Related
Oct 28, 2010
I am new to android.I have a list view in one activity. Displaying data in it... I want to use another activity as a tab-bar for 1st activity which allow user to switch to other activity... Is there any way so that 2 different views can be displayed in 1 activity. And then how can i start a new activity inside this activity. Like when user click on any button in tab-bar the corresponding activity should be start but we should not Re-initiate tab-bar view...
View 1 Replies
View Related
May 8, 2009
I basically have three activities X, Y, Z and I want only one instance of each but I want control over the navigation and I can't do that by putting all three activities in one task because of the stack structure.
Here is a scenario, from X I launch Y given a certain "id" which correspondence to specific data in the DB, Y inflates and populates it's views, then I go back to X and launch Y again with a different "id" in the intent, I don't want the overhead of launching the activity and inflating the views again, anyone know how to do this?
I tried using singleInstance, but the problem is that I can't send the result code back to an activity in a different task.
View 4 Replies
View Related
Apr 6, 2009
I want to display the status of the activity execution on the screen using the TextView while activity is executing. I am appending the String messages at different stages of execution in the TextView, which is defined in the Layout main.xml (e.g. TextView.append("Server started..").
For e.g. I am running socket communication application in which my android application is the server and it is receiving the messages from the local desktop. So in this application I want to show "Server started.." message when socket server on android started , then a messge "waiting for message.." and then "message receivied.." when message received by android server.All 3 steps are the part of a single activity.
But in my case, I am getting all 3 messages at a time after activity execution completed. Is there any API available, using which I can show the status during the execution also.
View 20 Replies
View Related
Jun 17, 2012
I have several textviews in an activity. I then have a button that I want to be able to click that will update the textview.
I want to do this without having to create multiple activities.
How do I go about I guess refreshing the current screen with new information?
View 7 Replies
View Related
Jan 6, 2010
I have a simple ListView and on that ListView I have placed a number of custom defined Views. The CustomView has ImageView and two TextViews.
The CustomView also has a "stateful drawable" as background, so that the background image (a 9-patch) changes if you press the Row in the ListView. When pressing the Row, the background image changes to a Red-ish thing.
The problem is that when the background changes from the default greyish, all the Views in the CustomView (ImageView and TextViews) still have their greyish background and thus creates very ugly greay boxes on top of the now redish background.
What is the best way to solve that problem? I hoped that such things were handled automatically (as it is done in for example .NET), but I was wrong it seems.
View 1 Replies
View Related
Oct 5, 2010
My application opens in Activity A1. None of the views in A1 are focused at startup, until I use the arrow keys to navigate through the views. A button press in A1 launches activity A2. When A2 opens, the first Button in A2 is focused by default. I do not want this happen. What I want is when A2 opens, none of the buttons are focused until arrow keys are used to naviagte through them(just like it is in A1).
View 1 Replies
View Related
Apr 15, 2009
I have custom view and once some action occur in it (say touch/key event) I'd like to call some code in my activity. My question is if broadcasts (intent filters/broadcast receivers) are good communication mechanism for such thing? If not, what is normal/android preferred way to do it?
View 5 Replies
View Related