activity-lifecycle

android - There is no default constructor for ArrayAdapter

让人想犯罪 __ 提交于 2019-11-29 07:58:49
I m making adapter to adapt my book collection to be visible in list view. Issue is solved if I add super(context, position): public BookAdapter(Context context, int position, List <Book> updatedBooksList) { super(context, position); this.context = context; this.booksList = updatedBooksList ; } However, I want to know why I need this argument (int position) and call superclass constructor? protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Also, in the broader sense why do we always(?) need to call super.onCreate like here in every onCreate? Aren't we

BufferQueue has been abandoned: When playing video with TextureView

浪子不回头ぞ 提交于 2019-11-29 04:02:02
问题 Every time I pause my activity (actually Fragment) to go to another app, upon returning with onResume I try to resume the video playing but it does not play: I get a blank screen. Upon investigation, I see the following in the Logcat E/BufferQueueProducer: [unnamed-23827-0] queueBuffer: BufferQueue has been abandoned E/MediaPlayer: error (1, -38) E/MediaPlayer: error (1, -38) E/MediaPlayer: error (1, -38) E/MediaPlayer: error (1, -38) E/BufferQueueProducer: [unnamed-23827-0] connect(P):

How to simulate killing activity to conserve memory?

守給你的承諾、 提交于 2019-11-29 02:50:53
Android doc say: "When the system, rather than the user, shuts down an activity to conserve memory, ... " But how to simulate this situation?I want to debug the onRestoreInstanceState(Bundle) method,but don't know how to. numan salati You can't do it in an automated way b/c its completely non deterministic. See my answer here: https://stackoverflow.com/a/15048112/909956 for details. But good news is that all you need to do is just simulate calling onSaveInstanceState and you are indirectly testing this low memory situation. onSaveInstanceState can be triggered by: losing focus (by pressing

Is onResume() called before onActivityResult()?

天涯浪子 提交于 2019-11-28 17:08:31
Here is how my app is laid out: onResume() user is prompted to login If user logs in, he can continue using the app 3. If the user logs out at any time, I want to prompt login again How can I achieve this? Here is my MainActivity: @Override protected void onResume(){ super.onResume(); isLoggedIn = prefs.getBoolean("isLoggedIn", false); if(!isLoggedIn){ showLoginActivity(); } } Here is my LoginActivity: @Override protected void onPostExecute(JSONObject json) { String authorized = "200"; String unauthorized = "401"; String notfound = "404"; String status = new String(); try { // Get the messages

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

Is there a function in Android analogous to “int main” in C/C++ which contains the program's main loop?

人走茶凉 提交于 2019-11-28 07:01:23
Normally in a C or C++ program there's a main loop/function, usually int main () . Is there a similar function that I can use in android Java development? As far as an Android program is concerned there is no main(). There is a UI loop that the OS runs that makes calls to methods you define or override in your program. These methods are likely called from/defined in onCreate(), onStart(), onResume(), onReStart(), onPause(), onStop(), or onDestroy(). All these methods may be overriden in your program. The fundamental issue is that the OS is designed to run in a resource constrained environment.

Activity lifecycle - onCreate called on every re-orientation

喜你入骨 提交于 2019-11-28 03:47:25
I have a simple activity that loads a bitmap in onCreate . I find that if I rotate the device I can see from the logs that onCreate called again. In fact, because all instance variables are set to default values again I know that the entire Activity has been re-instantiated. After rotating 2 times I get an FC because not enough memory can be allocated for the bitmap. (Are all instances of the activty still alive somewhere? Or does the GC not clean up fast enough?) @Override public void onCreate(Bundle savedInstanceState) { File externalStorageDir = Environment.getExternalStorageDirectory();

How to simulate killing activity to conserve memory?

╄→尐↘猪︶ㄣ 提交于 2019-11-27 21:59:23
问题 Android doc say: "When the system, rather than the user, shuts down an activity to conserve memory, ... " But how to simulate this situation?I want to debug the onRestoreInstanceState(Bundle) method,but don't know how to. 回答1: You can't do it in an automated way b/c its completely non deterministic. See my answer here: https://stackoverflow.com/a/15048112/909956 for details. But good news is that all you need to do is just simulate calling onSaveInstanceState and you are indirectly testing

Life cycle of Android Activity after pressing Back button

血红的双手。 提交于 2019-11-27 18:10:13
I am little confused between the life cycle of two activities. Suppose I have Activity A and Activity B. B is called From A i.e A ----> B . Now currently B is on the screen and I pressed back button. Here I want know:- is there any memory still available for B (Active) or B 's memory is flushed(Inactive). Jitesh Upadhyay Suppose there is an activity A, from which you launch activity B. If, while in activity B, you hit the back button, you are popping activity B off the stack and B will not be in the activity stack any longer. Whenever you push an activity to the stack, onCreate is called, and

OnPause and OnStop() called immediately after starting activity

我的未来我决定 提交于 2019-11-27 17:36:14
I have an activity that needs to turn screen on(if offed) when it is started. So in onCreate, I have: this.getWindow().setFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); Using this with help of wakelock in broadcasr receiver , I am able to cause my activity to display whenever it is started from broadcast receiver. But problem is very strange