Skip to main content

Posts

Showing posts with the label activity

Android lifecycle weirdness with singleTop and foreground service?

Here's the scenario: Start Activity A Activity A starts service S Service S runs in foreground mode and shows up a notification which when pressed takes the user to Activity B (which has launchMode="singleTop") Activity B shows up Press HOME Go into DDMS and kill your application process to simulate that your app died (press red STOP button) Android will say "Rescheduling crashed service in 5000ms" (sometimes longer) Service S restarts and notification is shown. Press the notification icon when the service restarts... ...at this time, Android will recover both Activities A and B due to the fact the process ended unexpectedly. But despite the fact Activity B is singleTop android will spawn it AGAIN because the user clicked on the notification. This results into having A -> B -> B on the activity stack. Pressing back will take you again onto the first recovered instance of Activity B. Can someone from the Android tea

Android: how to open new intent from ListView, hosted in TabHost, inside same FrameLayout?

I looked through tons of articles how to open new Activity from ListView hosted by TabHost. I have a TabHost Activity, one of the tabs has ListView, with clickable list items. On item click, I want new Activity to be opened in the same FrameLayout. My code for calling new Activity looks as following: Intent intent = new Intent(v.getContext(), displayRSS.class); this.startActivity(intent); This opens just new Activity. I want new Activity to be opened instead of current ListActivity. Would appreciate any possible solutions on this.

Android Activity causing Service crash due to heap fragmentation

I have an Android app (activity) which also has a corresponding service. The service is started by the activity and is supposed to run continuously even when the activity is stopped. When the activity is started again it can bind to the service and query it. Sometimes the activity gets destroyed and created by the OS. This should not affect things, the activity should just be re-created and be able to bind to the service again. This basically works. However... I have found that both the Dalvik VM heap and the native heap are non-compacting and therefore constantly increase in size until the activity runs out of memory and crashes (even though the total memory usage is actually constant and not leaking). This is much exacerbated by destroying and re-creating the activity since a lot of allocations are done during the creation process. This pretty much guarentees that the activity will crash after a number of restarts. This doesn't bother me that much, but what then happens

Contexts, AsyncTask and rotation changes

Is it a good practice to use getApplicationContext() working with AsyncTask in order to do not have to attach and detach the Activity to avoid memory leaks when rotation changes occur and the Activity is destroyed ? I thing it should be correct, as I actually need a Context that depends on the hole application, not the Activity itself. And what is more, in those cases in which is better to use the Activity as context (because you need access to the Activity showing)... Instead of detaching it (assigning to null) when it is destroyed and then assign the new instance in onCreate() , could be just avoid detaching? So, just reasigning the new instance, this way, we could avoid problems of NullPointerException because there would always be a context to use! Thanks in advance!

Android - Running heavy computations in background and returning the result to an Activity

I have implemented some computationaly heavy functions into my application. Depending on the type of input it can take up to several minutes for a thread to return. During this time, I want the user to be able to work with other activities to perform different tasks (i.e. prepare data for the next run). Then, after the Service has finished it's computations, the user should be notified with a Toast that the result is ready and that he should check back to the Activity he started the Service in. Unfortunately I'm stuck at this point. Is it possible to somehow communicate with an Activity which is destroyed at the moment? Like modifying the saved state, so that when it get's recreated the result will be displayed. The only way of communication I did find was via broadcasting from the Service, but this requires the Activity to listen, which is not possible as it doesn't exist at the moment the Service finishes. The only solution that occured to me was writing a file

Can I have an activity create another activity and wait for it to return information?

I want the user to be able to click a button and move to a different activity to input some information and then press a button to "submit" that information to the previous screen. Home Screen --button press--> Input Screen --"submit"--> Home Screen Is there a way to start the input screen activity and have the home screen wait for a response? This is the code I have now. Intent inputIntent = new Intent(this, InputActivity.class); try { // Attempt to start the activity startActivity(inputIntent); return true; } catch(ActivityNotFoundException e) { System.out.println("Cannot find activity for intent: " + inputIntent.toString()); return false; } I guess not only am I asking how to have the home screen "wait," but it would also be ideal to get back to the same home screen (not creating a NEW homescreen from the input screen).

Two launcher activities

I have two activities marked with intent filter <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.package" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" /> <application android:name=".MyApp" android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <!-- work order activity --> <activity android:name=".app.WorkOrderActivity" android:label="@string/work_order" android:taskAffinity="com.package.task_for_work_order_activity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- inventory activity --> <

Android Exception trying to open a new Activity - Surface::lock failed, already locked

When I try to open a new activity on a button press i get an Exception : 01-19 14:55:08.327: E/Surface(15454): Surface::lock failed, already locked 01-19 14:55:08.327: E/SurfaceHolder(15454): Exception locking surface 01-19 14:55:08.327: E/SurfaceHolder(15454): java.lang.IllegalArgumentException I have a game that draws on a surfaceview canvas with a thread, that runs with the main process, I'm trying to open a new dialog box for input and nothing worked so I'm simply trying to open a new Activity that will Exception, I'm using the lock and unlock and well synchronized, I tried stopping the thread and even placing a couple of views. Any help is good Thanks.

SQLite and Activity updates

I have a neat, working SQLite database on Android that records species observations. I am then using JSON (successfully) to verify observations entered against a set of parameters on a remote database. On verification, a flag in the database is updated to say that this process has been done. But, when I view my main activity (Text, the values for observations with flags after verification don't update. My activity order is: Main activity (obs = 0 from database) Obs Entry activity Main activity (obs = 1 with flag A from db) Data management activity, verify button Verify done activity, main button Main activity (obs = 1 with flag A from db) If I exit, or leave it for a while, then come back in to Main activity, the database is being polled correctly and obs = 1 with flag B from db. So I know my database is right and the SQL is correct too. Could it be that I'm declaring my buttons at the wrong point for the Activity to correctly resume()? My code

android, uninstall and install into the same activity?

I am trying to do an upgrade version process for apk files ... How can i do to run uninstall and install Intent calls into the same activity? If i do , uninstall intent, Uri packageURI = Uri.parse("package:" + paqueteId); Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,packageURI); startActivityForResult(uninstallIntent, RESULT_OK); is there anyway to wait for the uninstall finish and then continue running the activity code ... and then launch the install intent ??? thank you