activity-lifecycle

IllegalArgumentException with Otto Event bus in Fragment instance

给你一囗甜甜゛ 提交于 2019-12-18 10:55:18
问题 I am using Otto Event bus to subscribe to certain events in a ListFragment. The bus instance is stored and created in an subclass of Application, in other words, it bus should work as a singleton. It seems like this is not a case... The fragment is registering to the bus in onActivityCreated(Bundle) and unregistering in onDestroy() . This does not work as it should. I have gotten several crash reports from devices where the app crashes when calling unregister() (java.lang

Retrieve an activity after Time out warning notification

送分小仙女□ 提交于 2019-12-18 07:08:39
问题 I'm trying to implement time out notification. Here is what I want to do. If app goes to the background mood, after 5 minutes it should warn the user that app will be signed out. After this notification, if user opens the app, it should ask for the password, if user inputs correct pass, it should retrieve the screen that he left 5 mins ago. My problem is that I cannot save the activity that user left in order to retrieve after they input password. Here is what I've done so far: I added a

android - There is no default constructor for ArrayAdapter

蹲街弑〆低调 提交于 2019-12-18 05:09:07
问题 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

Prevent Android activity from being recreated on turning screen off

假如想象 提交于 2019-12-17 19:34:30
问题 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

Why implement onDestroy() if it is not guaranteed to be called?

不打扰是莪最后的温柔 提交于 2019-12-17 10:33:33
问题 According to the android Activity Lifecycle, the only callback guaranteed to be called (if an activity ever leaves the Running state, which is typically expected) is onPause() . So, I must assume that there are scenarios in which it makes sense to implement onStop() and onDestroy() although they are not really guaranteed to be called. I understand that onStop() should be implemented when it's possible for an activity to return to the Running state via the Stopped state (why would it do that

Why does calling getWidth() on a View in onResume() return 0?

扶醉桌前 提交于 2019-12-17 07:37:47
问题 Everything I've read says you can't call getWidth() or getHeight() on a View in a constructor, but I'm calling them in onResume() . Shouldn't the screen's layout have been drawn by then? @Override protected void onResume() { super.onResume(); populateData(); } private void populateData() { LinearLayout test = (LinearLayout) findViewById(R.id.myview); double widthpx = test.getWidth(); } 回答1: A view still hasn't been drawn when onResume() is called, so its width and height are 0. You can "catch

Why is NPE thrown when finishing Activity?

可紊 提交于 2019-12-14 01:05:28
问题 I have an error that has been driving me crazy for days. Unfortunately, I can not show you the code for two reason, my boss will not appreciate it and the codebase is too large to share. The error occurs whenever the Activity is finishing. Weather it be because I call finish() or because the os destroys it. The question is, what is (or could) cause execPendingActions() in FragmentManagerImpl to throw a NPE at line 1196. Here is the stacktrace: FragmentManagerImpl.execPendingActions() line:

Disabling Re-execution of Async Task on finishing of foreground activity

一曲冷凌霜 提交于 2019-12-13 06:06:39
问题 Case: I am using Async Task for showing some list. When I click on any item of listview another activity comes foreground of last activity. This foreground activity contains a finish button through which the foreground activity finishes. Problem: When i press finish button the foreground activity finishes but that last activity having the Async Task executes again. Need: I want when i press finish button then only foreground activity finishes and background activity having Async Task must not

How to pass and manipulate objects between activities using intents

别来无恙 提交于 2019-12-13 02:08:01
问题 This is my first issue with the Android lifecycleand I feel somewhat helpless: In Activity A there's onCreate. That's the spot where I create an ArrayList called playerNames and ArrayList called moves . Also there's some more stuff happening in oncreate. In A's onStart I create a flag so I know which Activity is running in case I'd like to close all at once. In onDestroy the flag is set back to null. Eventually I make an intent to get to Activity B where I take the moves list along. Works

Activity layout blinking after finish() is called

余生颓废 提交于 2019-12-12 13:09:53
问题 When I open my app, an Activity is started, and inside its onCreate method I'm checking some conditions. If the condition is true, I finish my current Activity and open another one. The problem is: The first activity blinks on the screen and then the second one is opened. The code is below: public class FirstActivity extends Activity { @Override protected final void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); //some code here... checkSomeStuff();