android-lifecycle

Why are lifecycle methods in activity class defined with protected access specifier

房东的猫 提交于 2019-12-04 09:46:34
Why are the lifeCycle methods in android have access specifiers as protected ? what i understand about Access-specifiers is as below :: But why should we need to make all the life-cycle methods as protected I notice this when i override the lifecycle methods I know over-riding the methods of Activity class as methods in Activity class are defined protected But why are they defined as protected Sam They are protected for encapsulation within the framework package android.app and subclasses. They are to be called by android.app.ActivityManager (same package) only. Depending on the method

On Android, can I register for a callback that tells me if Bluetooth is turned on or off?

佐手、 提交于 2019-12-04 09:08:59
I need to know inside my app whether bluetooth is on or off. Or if bluetooth was turned on or off e.g. from the OS settings pulldown menu. I thought I could do this in the Activity's onResume() . But it turns out that the activity is not paused when the Android OS's settings "pulldown menu" (the one that is accessed by pulling down with a finger from the top edge of the screen) is opened. I need to update my UI when bluetooth becomes available or unavailable. Can I register for a callback (e.g. a BroadcastReceiver ) or any other callback to let the system tell me when Bluetooth availability

Application crashes on rotation without stackTrace

陌路散爱 提交于 2019-12-04 08:17:28
I'm having a very strange problem with my app, which consists of an Activity and 2 Fragments (android.support.v4.app.Fragment). The problem is when I rotate my tablet : the app crashes right away. A few days before, everything was working fine, but I had to change packages name, that threw a few errors but I manage to correct them. Problem appeared right after that, but I just can't find where is the error. Here is the Logcat I get right after the app is destroyed, restarted, resumed and created : 10-08 17:00:14.930: D/dalvikvm(18155): GC_CONCURRENT freed 394K, 8% free 7792K/8455K, paused 1ms

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

痞子三分冷 提交于 2019-12-04 03:33:36
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? 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 it. Anyway, this is the best way that I see: 1.Create a boolean variable inside your Activity public class

is a view's “tag” restored when the activity whose layout contains the view is recreated?

限于喜欢 提交于 2019-12-04 02:17:07
The docs concerning Activity recreation state: By default, the system uses the Bundle instance state to save information about each View object in your activity layout (such as the text value entered into an EditText object). So, if your activity instance is destroyed and recreated, the state of the layout is restored to its previous state with no code required by you. The docs for View.setTag(Object) state: Sets the tag associated with this view. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a

performing pause of activity that is not resumed after recreate method

五迷三道 提交于 2019-12-04 01:25:06
I have a project for HoneyComb and I get an error after use recreate() method at onResum() method in my main Activity. 11-10 22:05:42.090: E/ActivityThread(1917): Performing pause of activity that is not resumed: {com.blogspot.honeyapp/com.blogspot.honeyapp.Main} 11-10 22:05:42.090: E/ActivityThread(1917): java.lang.RuntimeException: Performing pause of activity that is not resumed: {com.blogspot.honeyapp/com.blogspot.honeyapp.Main} 11-10 22:05:42.090: E/ActivityThread(1917): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2517) 11-10 22:05:42.090: E/ActivityThread(1917)

Stop handler after the fragment has been destroyed

旧时模样 提交于 2019-12-04 00:09:22
I have a Fragment which sets up a ListView and creates a Handler to update the Listview periodically. However, it looks like the Handler still runs after the Fragment has been destroyed. The following is the code. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //boilerplate code final Handler handler = new Handler(); handler.post(new Runnable() { @Override public void run() { assignAdapter(); handler.postDelayed(this, 15000); } }); return v; } Updating the ListView after the destruction of the Fragment causes the app to crash. How

Using system.exit(0) in onDestroy() (Android)

情到浓时终转凉″ 提交于 2019-12-03 21:18:18
I know that it is not recomended to use system.exit(0) in an Android application, but I was wondering if it would be ok to use it in onDestroy() since the application is allowed to be killed at that point? The reason I am asking is in relation to this question. Do not rely that onDestroy will be called. There are situations where the OS will kill your application without calling your onDestroy . Just a word of advice, of course, as it does not directly apply to your scenario. If system.exit(0) was not called because the app is already killed, I'd say you're OK. ;-) If your Activity.onDestroy

Is Fragment.onStop() guaranteed to be called?

我只是一个虾纸丫 提交于 2019-12-03 16:23:39
From the table at this link: http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle we can see that an Android Activity is not killable until after onStop() has been called (for Honeycomb and beyond). Do we have the same (documented) guarantee for Fragments? Would greatly appreciate someone pointing me at documentation where it is clearly stated. Edit: As has been pointed out [Fragment.onStop] is generally tied to Activity.onStop of the containing Activity's lifecycle. http://developer.android.com/reference/android/app/Fragment.html#onStop() But this doesn't tell me

Distinguish between pushing “home” button and opening another Activity

核能气质少年 提交于 2019-12-03 15:46:26
I have three activity: - SplashActivity - MainActivity - PlayerActivity Of course the app starts with SplashActivity, then it starts MainActivity and closes. MainActivity in some moment starts PlayerActivity and goes to backstack. (MainActivity is alive but is onStop) Then I need open MainActivity and set PlayerActivity to background (PlayerActivity is alive but is onStop). Then I need open PlayerActivity again and set MainActivity to background. So PlayerActivity and MainActivity often gets onPause() and onStop() without onDestroy when app switch one to another and back. I need finish all