android-lifecycle

Handling native threads during onPause()

独自空忆成欢 提交于 2019-12-13 14:26:04
问题 So I have an android game that has some tight integration of Java and C++. Both Java and C++ side use a lot of threads (polling, loading, calculating). Most of the threads are meant to run continuously in parallel with the rest of the app (for example to stream music from MP3). Some threads are meant to be run once (like submitting a large file to a cloud service). Now the question is what's the best way to handle native threads during onPause/onResume events? Is it okay to just leave as they

Android: When a service is killed, how can we persist the service state for later restoration?

给你一囗甜甜゛ 提交于 2019-12-13 13:12:39
问题 We have created an app that is essentially a timer/stopwatch with some decked out features. We defined a service that ticks the clock and alerts listeners (activities, etc.) who are subscribed to certain timer events. We would like to be able to save the state of the timer/stopwatch (elapsed seconds, time until next event, user-provided config etc.) whenever android kills our service (for memory recollection), and then restore the state of the service when the app is restored by the user. For

Prevent dialog to be opened multiple times when resuming activity

坚强是说给别人听的谎言 提交于 2019-12-13 13:04:36
问题 In my Android application, in order to ask the user if he/she wants to resume a current game, I display a dialog saying "Do you want to resume current game? Yes - No" on the main game activity. The thing is that if I resume various times this activity without answering the dialog, then I get several dialogs, on top of each other, which is obviously not my goal. I could easily avoid this behavior using a Boolean var, but I was wondering if the Dialog class had a kind of option preventing to be

Android - Prevent onResume() function if Activity is loaded for the first time (without using SharedPreferences)

六月ゝ 毕业季﹏ 提交于 2019-12-13 12:04:32
问题 In my current application the onResume function is triggered when I load an Activity for the first time . I looked into the Activity Lifecycle, but I didn't find a way to prevent this from happening. Can I prevent the onResume() function from loading when an Activity is loaded for the first time, without using SharedPreferences? 回答1: Firstly, as RvdK says, you should not modify the Android Activity lifecycle, you probably have to re-design your activity behavior in order to be compliant with

My Application won't start up?

人盡茶涼 提交于 2019-12-13 11:16:14
问题 I'm not really sure why my application won't start up, I get no errors and I have no idea what's going on? I'm pretty new to android and this is just a basic calculator, but it keeps crashing every time I start it up. ***************Main Activity.java********************** package com.example.alex.myapplication; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends ActionBarActivity

Handle ToggleButton in onResume()

情到浓时终转凉″ 提交于 2019-12-13 08:05:43
问题 I have written a program in which I am using Timer and controlling that timer using Toggle states. Toggle's default state is OFF , once I make changes in toggle state from OFF to ON Timer starts, and when I again change to OFF it stops the Timer as per requirement. But problem starts when my Timer is ON and I switch to other activity and then again come back to ToggleActivity and then do changes in toggle state from ON to OFF - it still runs Timer ... Note: when I use finish() or back press,

getLastNonConfigurationInstance() substitute android

喜夏-厌秋 提交于 2019-12-13 04:29:36
问题 When i use getLastNonConfigurationInstance() The Eclipse IDE tells me that it is depreceated.Can anybody tell me the substitute of this method? 回答1: From documentation: This method was deprecated in API level 13. Use the new Fragment API setRetainInstance(boolean) instead 来源: https://stackoverflow.com/questions/18163434/getlastnonconfigurationinstance-substitute-android

ImageView causes crash but only when resuming from standby mode

自古美人都是妖i 提交于 2019-12-13 04:25:45
问题 I got an Activity class that uses two other classes; one of them extending ImageView and one that extends BaseAdapter like so: My ImageView class does some progresses when it is called and when I am starting it for the first time it does what I want it to. This is also the case if I press home button and then resumes. But for some reason it does not work if I resume from standby mode. (pressing the button on the phone that makes the screen dark) When I unlock the phone it crashes. It crashes

android - My app doesn't show in recent apps list

烂漫一生 提交于 2019-12-13 04:14:50
问题 I am working on an app and have just realised it doesn't show in the recent apps list. I have 2 activities in the app and no matter which I am on when I hit the Home key, the app isn't shown in the recent apps list. I have seen this question: SO Question but putting the category stuff in the manifest hasn't worked for me. Below is the part of my manifest: <application android:label="@string/app_name" > <service android:name=".UploadService" android:exported="false" /> <service android:name="

Killing an Android App with the Home Key

对着背影说爱祢 提交于 2019-12-13 03:58:53
问题 I have an android app, and when the Home key is pressed I want it to terminate. Period. I dont want it hanging around running in the background. I just want it terminated. What's the best or prferred method to do this? 回答1: No you don't. Trying to "kill" your app is an Android antipattern. Trying to catch the home key is also an Android antipattern. There is a vast amount of material substantiating these points. If you think you do want your application killed, you're just plain wrong. 回答2: