Android : Return A Result (startActivityForResult) From A TabHost Activity?
Mar 23, 2010
I have 3 classes in my example:
Class A, the main activity. Class A calls a startActivityForResult:
Intent intent = new Intent(this, ClassB.class);
startActivityForResult(intent, "STRING");
Class B, this class is a TabActivity:
Intent intent = new Intent(this, ClassC.class);
tabHost.addTab...
Class C, this class is a regular Activity:
Intent intent = this.getIntent();
intent.putExtra("SOMETHING", "EXTRAS");
this.setResult(RESULT_OK, intent);
finish();
onActivityResult is called in Class A, but the resultCode is RESULT_CANCELED instead of RESULT_OK and the returned intent is null. How do I return something from the Activity inside a TabHost?
I realize that the problem is that my Class C is actually running inside of Class B, and Class B is what is returning the RESULT_CANCELED back to Class A. I just don't know a work around yet.
View 4 Replies
Oct 1, 2010
i seem to have a classic task, yet i can't find any examples on how to do it.i want to download something. well i call a web service and get a response but its pretty much the same.in order to do this i have an activity that starts a service that spawns a thread that does the job.now i would like to use the data i got in the activity that started the service.(i assume that starting another activity to handle the job of displaying the result would be simple)my problem is how does the service notify an activity (the one that started it or another one) of something.
View 1 Replies
View Related
Sep 2, 2009
I meet an issue: my activity cannot return result.
I created an activity which has one TabHost. I added three tabs using mTabHost.addTab. Every tab will launch an activity(activity A, activity B, activity C). In activity A, it will call startActivityForResult to start activity A1. The issue is activity A cannot get any result after A1 finish.
What is the reason? How should I do if I want to get return value?
View 3 Replies
View Related
Jan 21, 2010
According to my research, which includes reputable sources (Mark Murphy et al), the most preferred way of polling a remote source and presenting said data to the user is by creating a service and using AsyncTask within that service to do the polling. I have done that.But, when I read the docs there seem to be several "Threading Rules" that conflict with this way of doing things: "The task instance must be created on the UI thread." and "execute(Params...) must be invoked on the UI thread." As stated, I have created the task instance on the Service thread (not the UI thread). Am I missing something? Also, when the AsyncTask finished, I sent out a Broadcast on onPostExecute, which is then picked up by the Activity, telling it to retrieve the final value again from the service (since I couldn't obviously update the UI from the service). I couldn't figure out any other way to return the result of the AsyncTask. Is this the correct practice?
View 8 Replies
View Related
Nov 18, 2010
I have SQLITE DB query which returns me one record at a time.
This is the query :-
rawQuery("SELECT id, category_id, title, text FROM customer WHERE (reads = (SELECT MIN(minReads) FROM categories)) AND status = 'a' ORDER BY rating DESC, rand_index DESC LIMIT 1 ",null);
If I want to fetch next record as we are applying limit in my sqlite query above i m unable to get next record. Limit 1 is necessary as i have thousands of record in my db.
How can I fetch next record without modifying the existing query. I cannot apply loop on this as I have lots of records and I don't want all the record at the same time. I want it to be fetched dynamically one by one. I want to be be something like where I can store result in an array as I might need old record as well while getting next record.
View 2 Replies
View Related
May 17, 2010
I have MainActivity which is an Activity and other class(which is a simple java class), we`ll call it "SimpleClass".
now i want to run from that class the command startActivityForResult.
now i though that i could pass that class(SimpleClass), only MainActivity's context, problem is that, u Cant run context.startActivityForResult(...);
so the only way making SimpleClass to use 'startActivityForResult; is to pass the reference of MainActivity as an Activity variable to the SimpleClass
something like that:
inside the MainActivity class i create the instance of SimpleClass this way:
SimpleClass simpleClass=new SimpleClass(MainActivity.this);
now this is how SimpleClass looks like: code...
now its working, but isnt a proper way of doing this? I`am afraid i could have some memory leaks in the future.
View 2 Replies
View Related
Nov 23, 2009
I have two buttons in an activity/view A0, b1 and b2 that respectively starts (for result) the activities A1 and A2. After tapping/clicking b1 I quickly tap b2 aswell. The result will be that both A1 and A2 are launched. Is there any obvious way to not have this behaviour, i.e. to "lock" A0? I am thinking of overriding dispatchTouchEvent to consume everything after the call to startActivityForResult, but it seems a bit much...
View 2 Replies
View Related
Nov 12, 2010
I got a question about Activity.finish(). In my Android code, there are 4 activities(A,B,C,D). The starting activity A calls startActivityForResult(intent, reqCode) to start activity B. B starts C, and then finish(), not waiting for result. C does exactly the same as B, starts D and then finish(). D will return some result, by setResult(resultCode).
When my code runs and activity D returns some result, A will catch a RESULT_CANCELED on onActivityResult(), even if RESULT_OK is returned in D. I guess the RESULT_CANCELED is from activity B, which has been terminated before D returns a result, rather than from D.
But, my question is, why activity A catch RESULT_CANCELED after D returns some result, rather than immediately after B is terminated? And, what should I do to make A catch results from D? Do I have to keep B and C alive, to pass results from D to A?
View 2 Replies
View Related
Jul 19, 2010
Is there an exception in the lifetime rules for a parent activity that's in the background after invoking startActivityForResult()? From my understanding, in low memory scenarios, the background activities are killed before the foreground. Does this rule still apply even if the background activity started the foreground one for the purpose of obtaining some result?
In this case, I think it would make sense for the foreground child activity to get killed first or to equalize the lifetime of the parent and child.
View 5 Replies
View Related
Jan 13, 2010
I've searched and I know it seems some people frown upon using activities within tabs, but moving past that...how would I restart a tabbed activity while still keeping the tabs visible? I have an activity in a tab, I use the menu to create a new activity to update the tab's activity displayed info, when I return from the menu activity I want the new information to be displayed in the tab's activity. I am using startActivityForResult() from the menu choice, but when I return and try to restart the activity...it wipes out the tabs above(I guess as expected, but I want to re-launch the refreshed activity within the tab).
Creating the tabs:
TabHost host = getTabHost();
Intent home_intent = new Intent(constants.HOME_ACTION,
null, this, homeTab.class);
Intent inbox_intent = new Intent(constants.INBOX_ACTION,
null, this, inboxTab.class);
Intent stats_intent = new Intent(constants.STATS_ACTION, null,
this, infoTab.class);
host.addTab(host.newTabSpec(constants.HOME_TAG)
.setIndicator(getText(R.string.home_label),
getResources().getDrawable(R.drawable.icon))
.setContent(home_intent));
host.addTab(host.newTabSpec(constants.INBOX_TAG)
.setIndicator(getText(R.string.inbox_label),
getResources().getDrawable(R.drawable.icon))
.setContent(inbox_intent));
host.addTab(host.newTabSpec(constants.STATS_TAG)
.setIndicator(getText(R.string.stats_label),
getResources().getDrawable(R.drawable.icon)).setContent(
stats_intent));
Return from the menu activity in the tab's activity(updating database info): code...
View 2 Replies
View Related
Aug 5, 2010
When user presses a button from a webview, I open a scrollview activity with some buttons and edittext fields.
Once the user enters the fields and presses the 'create' button, from scrollview activity, I want the results from the called activity to be accessible. How can I do thi?
View 1 Replies
View Related
Sep 25, 2009
The application I'm currently working on consists of several dialogs and there is an issue with one dialog I still haven't found the cause.
Running the debugger the execution reaches the following two lines:
CODE:.................
And then the onCreate() method in DlgLogin class executes as well
But the login dialog doesn't appear. If I leave the device idle for such long period of time that the screen turns off and then press any button on the device to turn it on the login dialog appears.
The dialog of course should appear immediately but so far haven't found the cause of the problem.
View 1 Replies
View Related
Nov 17, 2010
I must be overlooking something because I am unable to get my TabHost to display in my Activity class.I am getting the dreaded force close when I try to run the app.It will work if I extend TabActivity, but I can't do that [details at the bottom] because once I move the code from my prototype project its going to be in a custom class that inherits from Activity.
View 2 Replies
View Related
Dec 8, 2009
I have created a TabHost and in 1 of the tab, I have added the content using
mTabHost.addTab(mTabHost.newTabSpec("tab1")
.setIndicator(getString(R.string.dialerIconLabel),
getResources().getDrawable(R.drawable.ic_tab_dialer))
.setContent(intent));
Is it possible for me to switch the content's activity programatically after I called 'addTab of TabHost'?
View 1 Replies
View Related
Mar 10, 2010
I'm doing some network job in AsyncTask. Sometimes it requires communication with user. (connection is dropped, session is expired and so on). I want to pop up a dialog or launch an Activity, and then, depending on user's input, stop the job or redo it. I can launch any Activity from AsyncTask, but how to get result back? It seems to be possible only if I launch new Activity from another Activity. What are possible solutions?
View 5 Replies
View Related
Jul 16, 2009
I know that the following code should show and hide a tiny circular progress bar with the following code in Android:
CODE:.............
The problem is that I am using a TabHost and I need to be able to do this from one of the "child" activities. Is there any way I can go about doing this?
View 2 Replies
View Related
Jan 26, 2009
I have an application with contains multiple activities. The main activity will start the others ( use startActivity() ) depends on user event, when an activity close, it calls finish() and return back to main activity. It appears to behavior like that.
However, the "problem" I see is main activity's onCreate function is called every time. I think the the main activity should be placed in the activity stack and simply push to front when others exit, therefore only onResume, onStart are called. Is there some flag I need to set or I misunderstand the activity behaviro?
In child activity, besides calling finish() or startActivity for main activity, what is other way to move main activity to front?
View 2 Replies
View Related
Apr 15, 2010
Experts: My MainActivity launches a SubActivity by calling: startActivityForResult(intent, REQ_CODE); The SubActivity shows a dialog that has two buttons: Yes, No For the dialog, I've the following code: public void onClick(DialogInterface dialog, int whichButton) {/* User clicked OK */setResult(DialogInterface. BUTTON_POSITIVE) ;finish();
View 2 Replies
View Related
Feb 11, 2010
I have a Service which needs to receive data from external packages. So, to locate the data providing external packages, I use activity- filter and PackageManager.queryIntentActivities function to locate the interesting packages. Now, from each such package, I need to get a ContentProvider URI. So I want to start the external Activity and the external activity will return a result to my service - something like "startActivityForResult". The problem is that there is no way to call "startActivityForResult" from a Service, only Activity can do that, and my project does not have any Activity, and probably can't show UI for the user.
The bottom line: Can anyone suggest a way to get ContentProvider URI from an external package, while my package has only a Service?
View 22 Replies
View Related
Aug 30, 2010
I am launching a mail activity by
//Sending mail final int SENT_MAIL = 1;
startActivityForResult(Intent.createChooser(i, "Send mail"),SENT_MAIL);
and in
onActivityResult(int req, int res,Intent data)
I am trying to find the result of email sending, so as to confirm if my mail was sent or was discarded by the user. I am receiving null for Intent data.
i.e. data =null
parameter in onActivityResult(int req, int res, Intent data), res is always 0.
ie. res = 0;
View 1 Replies
View Related
May 4, 2009
I am currently trying to launch a GPS settings activity using startActivityForResult....however it never seems to be calling my onActivityResult function after it exits. I noticed the docs mentioned that some Intent protocols are not defined to return a result, is this one such example? are there any flags that I could set to either make the settings activity call onActivityResult, or even better make my activity block until the launched activity returns?
View 5 Replies
View Related
Mar 12, 2010
I hope the title says it all: I've got Activity A which fires up the Camera intent via:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);
After the picture is taken I can easily grab the picture in:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
But I'd like to receive the result in Activity B in which the image can be edited.
Right now I'm receiving the result in Activity A and pass it over to Activity B which results in showing the GUI of Activity A for a short while:
Intent i = new Intent().setAction("DisplayJPEG");
i.setClass(this, EditImageActivity.class);
i.putExtra("IMAGE_URI", uri);
startActivityForResult(i, REQUEST_EDIT_IMAGE);
Of course, I will need the result from Activity B in Activity A after the image has been edited. But that should work with:
setResult(resultCode, data);
So there has to be a way to do what I need. Please point me into the right direction.
View 3 Replies
View Related
Nov 14, 2010
I am developing an android application where I have a main-activity that contains a progress bar and a tabhost. the tabhost has 3 tabs.How do I from a tab-activity access the progress bar in the main activity? I want to be able to start and stop the progress bar when things changes inside each tab ativity.
View 1 Replies
View Related
Jul 25, 2010
I have a main screen with buttons to launch other subactivities. I have to press back button each time to go back to the main screen of my application. How do I finish a child activity and automatically return from the caller?
View 5 Replies
View Related
Jul 14, 2010
Despite similar question was asked, I have differnet situation: My app consists mostly of a background Service. I want to start external activities and get results back.I see several options:Create dummy Activity and keep reference to it for using its startActivityForResult. This consumes quite a lot of memory, as we know. Use Broadcast Intents instead of Android's results infrastructure: ask client activities to broadcast their results before closing. This kind of breaks the idea and not so performance-efficient. Use Instrumentation directly - try to copy code from startActivityForResult into my Service. Use Service interfaces - serialize and add AIDL connection to the Intent for starting an Activity. In this case Activity should call Service directly instead of providing result. The third approach feels closer to Android for me, but I'm not sure if it's possible to do - Service does not have its Instrumentation, and default implementation seems to always return null.
View 1 Replies
View Related
Nov 18, 2010
Activity A is main activity. Whereas Activity B is SearcActivity (Search Manager). Activity B is List Activity, so whatever result comes, result is displayed in the list. Once user clicks on the list, I want to get that list selected item to be returned to ActivityA.What I did. Code...
View 3 Replies
View Related
Aug 30, 2009
I've implemented an onSaveInstanceState function in the main activity of my TabHost-based application. I need to save the state of various objects I am keeping in memory that I have all marked as serializable, as well as some basic int and string values. I have stepped through my application and watched it call the onSaveInstanceState function and presumably save everything without any manner of exception or problem. The issue is that my onCreate function is being called with a null Bundle value every time after I start the application again. I'm really at a loss and unsure why it would call the save but not pass anything into the create.
View 1 Replies
View Related
Apr 20, 2010
I am trying to setResult after the BACK button was pressed. I call in onDestroy. So, how can I pass result from activity terminated by BACK button?
View 2 Replies
View Related
Nov 3, 2009
I've got a tab host activity started from a home screen shortcut. When my application starts it downloads information from a server using an AsyncTask. In the onPostExecute method of the AsyncTask I call setContentView to display the TabHost.When I start the homescreen shortcut by tapping on the shortcut using my finger everything works as expected, I download the information from the server and display the TabHost with the information in the tabs. However starting the application by navigating to the shortcut with the mouse wheel and then clicking on the shortcut with the mouse wheel leads to a trap in the framework code as soon as my application starts. This looks like a simple fix since mCurrentView is null at the time that this method is called - can this issue be addressed? Does anyone know of any workarounds?
View 5 Replies
View Related
Jun 1, 2010
I have two activities: a MainListActivity, and a DetailViewActivity. DetailViewActivity is set with android:launchMode="singleTop".
When clicking an item in the "main list" activity, it launches the "detail view" activity via:
startActivityForResult(detailIntent, REQUEST_CODE_DETAIL);
If I then call setResult(RESULT_OK, resultData); and finish(); from within the Detail activity, that resultData is received by the "main list" activity's onActivityResult(..) method correctly.
However, if I implement a "see previous"/"see next" type of navigation within the Detail activity, and implement it using singleTop, that result no longer gets sent back to the initial activity:
Intent nextItemIntent = this.createIntent(nextId);
nextItemIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
startActivity(nextItemIntent);
// at this point, my DetailActivity's onNewIntent() method is called, and the new data is loaded properly
But from here, when I call setResult(..) and finish(), my MainList activity never receives the new/updated result. Anyone know what I'm doing wrong?
View 1 Replies
View Related