lifecycle

Problems understanding the life cycle when screen goes off and on

a 夏天 提交于 2019-11-28 20:28:40
Information: My device is a Nexus One with 2.2 and I have tested two projects, one on 1.5 and one on 2.1. Problem: I have trouble to understand the life cycle of my application when the screen is turned off and on. Here is my output // activity starts 08-04 17:24:17.643: ERROR/PlayActivity(6215): onStart executes ... 08-04 17:24:17.643: ERROR/PlayActivity(6215): onResume executes ... // screen goes off 08-04 17:24:28.943: ERROR/PlayActivity(6215): onPause executes ... 08-04 17:24:32.113: ERROR/PlayActivity(6215): onStop executes ... 08-04 17:24:32.113: ERROR/PlayActivity(6215): onDestroy

Ninject caching an injected DataContext? Lifecycle Management?

China☆狼群 提交于 2019-11-28 19:56:46
I had a series of very bizarre errors being thrown in my repositories. Row not found or changed, 1 of 2 updates failed... Nothing made sense. It was as if my DataContext instance was being cached... Nothing made sense and I was considering a career move. I then noticed that the DataContext instance was passed in using dependency injection, using Ninject (this is the first time I have used DI...). I ripped out the Dependency Injection, and all went back to normal. Instantly. So dependency injection was the issue, but I still don't know why. I am speculating that Ninject was caching the injected

What is the lifecycle and concurrency semantics of Rhino Script Engine

℡╲_俬逩灬. 提交于 2019-11-28 18:38:44
I am interested in the lifecycle and concurrency semantics of (Rhino) Script Engine and associated classes. Specifically: Is Bindings supposed to be thread safe? Should multiple threads be allowed to share a single ScriptEngine instance? ... or should each thread construct a short-lived instance? ... or keep them in a pool? What happens if multiple threads concurrently call ScriptEngine.eval(...) ? Same questions for CompiledScript instances Same questions for interface implementations generated using Invocable.getInterface(...) ? Presumably, objects placed in Bindings follow Java's garbage

How to test code built to save/restore Lifecycle of an Activity?

﹥>﹥吖頭↗ 提交于 2019-11-28 18:35:58
How can I test all of the following methods code? I want to play scenarios when all of them are happening to see if my code works for save/restore process of an activity. So what should I do in the Emulator to get all methods tested? public class Activity extends ApplicationContext { protected void onCreate(Bundle savedInstanceState); protected void onStart(); protected void onRestoreInstanceState(Bundle savedInstanceState); protected void onSaveInstanceState(Bundle savedInstanceState); protected void onRestart(); protected void onResume(); protected void onPause(); protected void onStop();

onCreateView method gets called when? and How many times in Activity life cycle?

ぐ巨炮叔叔 提交于 2019-11-28 18:17:20
I wrote a little program looking like this: package com.example.lifecycle; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.util.AttributeSet; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; public class LifeLogger extends Activity { private String TAG = this.getClass().getName().toString(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_life_logger); Log.d(TAG,"onCreate event"); } @Override

How do I preserve a complex object across Activity restarts?

自作多情 提交于 2019-11-28 16:44:01
Say I have a Java Bean object which is serializable. I want to store it away safely when an Activity goes through onDestroy() on purpose (i.e. onSaveInstanceState() is not called). I am looking for a way which doesn't involve creating a database and write the object to that (mostly since a) Android's DB API is horrible and b) since databases make application updates a nightmare, because there is no decent support for applying migrations). I thought about serializing the object to a ByteArrayOutputStream, base64 encode that and write it to a SharedPreferences file as a string. Or is that too

How to use lifecycle method getDerivedStateFromProps as opposed to componentWillReceiveProps

末鹿安然 提交于 2019-11-28 16:16:23
It looks like componentWillReceiveProps is going to be completely phased out in coming releases, in favor of a new lifecycle method getDerivedStateFromProps : static getDerivedStateFromProps() . Upon inspection, it looks like you are now unable to make a direct comparison between this.props and nextProps , like you can in componentWillReceiveProps . Is there any way around this? Also, it now returns an object. Am I correct to assume that the return value is essentially this.setState ? Below is an example I found online: State derived from props/state . Before class ExampleComponent extends

How to use lifecycle method getDerivedStateFromProps as opposed to componentWillReceiveProps

[亡魂溺海] 提交于 2019-11-28 14:58:07
问题 It looks like componentWillReceiveProps is going to be completely phased out in coming releases, in favor of a new lifecycle method getDerivedStateFromProps :static getDerivedStateFromProps(). Upon inspection, it looks like you are now unable to make a direct comparison between this.props and nextProps , like you can in componentWillReceiveProps . Is there any way around this? Also, it now returns an object. Am I correct to assume that the return value is essentially this.setState ? Below is

why we can call getActivity() in onCreateView which run before onActivityCreated?

吃可爱长大的小学妹 提交于 2019-11-28 13:17:06
I really get confused with Fragment lifecycle , especially for the time to call getActivity() . Sometimes you cannot get Activity by getActivity() . And it always caused some puzzling bugs. Thank you for anyone can solve the puzzle. getActivity() can be null while your fragment is in process of preparation and about to be ready. The fragment life cycle is bound to callback methods. These method will be called somewhere in time while fragment is preparing. Fragment.onActivityCreated(Bundle) is the place when the fragment activity will not be null, i.e. getActivity() will be a valid instance. It

Prevent Android activity from being recreated on turning screen off

随声附和 提交于 2019-11-28 10:51:03
How to prevent an activity from being recreated on turning screen off? What I do Start Bejewels and go to the jewelry screen. Press power button shortly. The screen is turned off, but the device is not. Press power button again. What I see The same screen as before turning screen off. In case of my application (trivial one, just a web-app with a single WebView) the scenario is the following: What I do Start my app. The activity onCreate() method loads an URL into the WebView. Press power button shortly. The screen is turned off, but the device is not. Press power button again. What I see The