FAQ Database Discussion Community


Android how to stop refreshing Fragments on tab change

java,android,android-fragments,android-viewpager,android-lifecycle
I have the following code : MainActivity.java package com.erc.library; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.FragmentTransaction; import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.Color; import android.os.Bundle; import android.os.Environment; import...

If an activity is created by a listener, then the listener is destroyed, what happens to the task?

android,android-intent,android-activity,android-wear,android-lifecycle
I've got an Android wear class that extends WearableListenerService and which is creating an activity. The documentation says this about activities and tasks upon creation of the activity: A new activity is, by default, launched into the task of the activity that called startActivity(). Therefore my activity is being added...

is SQLite db remain after application shutdown?

android,sqlite,android-lifecycle
Very (very) basic question that unclear to me: Is SQLite db remain after application shutdown with all the data that was added to it or destroyed? If so (and I hope so), when is the the DB schema created during the app lifecycle? I would expect it to be created...

Android Studio Error “Perfoming stop of activity that is not resumed”

android,parse.com,android-lifecycle
When I run my app it just opens a white screen and stays there, it slows my whole phone down until I'm forced to shut it down. Logcat says that the first error is "Perfoming stop of activity that is not resumed". I don't really have a onResume on my...

Strange behavior of android application lifecycle

android,android-activity,android-lifecycle
Today I was trying to simulate low memory condition for an Android application in eclipse. But I have found a strange behavior. Let me describe the scenario. Start an activity and call another activity by pressing a button from first activity. Now from Eclipse->DDMS->Devices click on "Stop process". What I've...

What the equivalent of activity life cycle in iOS?

android,ios,objective-c,mapping,android-lifecycle
Actually, I would say that both iOS ViewControllers and Android Activities have their lifecycle methods. For example an equivalent of ViewController.viewDidLoad() is Activity.onCreate() ? Else I still need to know the equivalent of the other : OnStart() OnRestart() OnResume() OnStop() OnDestroy() OnPause() ...

Android Activity lifecycle, restarting app instead of restart activity

android,android-activity,android-lifecycle,restart
I developed an Android app recently. Everything goes well until I press home key on my devices. On one of my devices (which has more memory), activity resumes in right state and my app runs well. But on other device, activity kills after some seconds and when I resume app...

Android data is lost onCreate() after startActivity() for callback

android,twitter4j,android-lifecycle,activity-lifecycle,datapersistance
I have an android app which connects to twitter via twitter4j. In an activity there is a share button and a TextView. The flow is like below; User opens the activity starting onCreate() which populates the TextView User clicks "Share" Twitter activity is started for oAuth, user types account credentials...

What method is ran when user clears “Recent Apps” in Android

android,android-lifecycle,application-lifecycle
I have a music player with a noncancellable notification. In my onDestroy, i have a clearNotification method. However when I clear the app by holding the home button and clear recent apps, the music stops but the onDestroy method is not ran because the notification doesn't clear. So my question...

Support v7 ActionBarActivity, OnCreateOptionsMenu() called after each call to SupportInvalidateOptionsMenu()

android,android-actionbar,android-lifecycle,android-menu,android-optionsmenu
In my Activity which is a Support v7 ActionBarActivity, I have menu and a navigation drawer. When ever the navigation drawer is open I want to hide the menu items. I hide them in the onPrepareOptionsMenu(). As stated in the documentation from android, in order to trigger an onPrepareOptionsMenu() you...

How to do onBackPress dialog in fragment in android?

android,android-fragments,android-lifecycle,android-event,onbackpressed
I was working on create a dialog that pop up to confirm whether the user exit the page. In the past I used the activity so it has no problem. I just need to put the dialog inside the override onBackPress function, and call finish() if the user choose to...

Android preserving state inconsistencies

android,state,android-lifecycle
as a new android developer I'm trying to adopt the android mindset. I faced a problem while preserving the state of an activity, because onSavedInstanceState does not seem to work consistently between different versions of Android. Prior to version 3, onSavedInstanceState would preserve data even when the app got killed...

Android Simple Camera Control App crashes when returning from Stopped

android,camera,android-lifecycle
I was working through the developer.Android Tutorials on building a Camera App but I always encounter the following problem: When my app is put into the background, i.e. Stopped according to the activity lifecycle, and I try to return to it it crashes, telling me the App has stopped working....

Dagger inject onStart

android,android-activity,android-lifecycle,dagger
Research: Couldn't find anything similar. I have a Singletonand I inject it into my SecondActivity in the Constructor using InjectorUtil.inject(this);. I then call mySingleton.getPersonCount() and it gives me the count. My problem is that when I leave the app and return to it. From my understanding causing the onStop() then...

Android - Ensuring that Wakelock is released when a Service's process is killed by OS

android,android-service,android-lifecycle,android-wake-lock
I want my FusedLocationProvider to ping for location even when the screen is off. For this, in my service, I have a PARTIAL_WAKE_LOCK, to keep the CPU running and to ensure that the service continues to run even when the screen is off. That being said, I know the Android...

Activity loads data twice

android,android-activity,bundle,android-lifecycle
There is one Activity - called MainActivity. There is one xml - called activity_main. It contains a menu layout and game layout. Menu layout - contains a "Start Match" Button Game layout - contains a Listview with 4 String items (4 words...) and a "Done" Button When the app launches,...

Contradiction in Activity lifecycle diagram versus description of lifecycle

android,android-activity,android-lifecycle
I am not clear on what the situation is when an activity is "destroyed" by the OS. Let me explain why - in the diagram of the activity lifecycle here: http://developer.android.com/reference/android/app/Activity.html There is an arrow going directly from onStop() to 'App process killed' then an arrow from 'App process killed'...

Android: how to log all Activity methods calls?

android,android-lifecycle
I would like to have a quick way to be able to log all the calls to all the super methods called by the activity. I have tried this https://github.com/stephanenicolas/loglifecycle but for some reason it does not work with AppCompatActivity... I could ask my IDE to override all the methods;...

How to make phone's back button work like up from Action Bar?

android,android-activity,android-lifecycle
For some reason, pressing the back button causes some trouble. However, the back arrow on the action bar, which is the up navigation, does not have any problems. I saw answers to make the up button work like the back button, but I haven't seen any that make the back...

Android - save value of member field in Fragment class

java,android,android-fragments,sharedpreferences,android-lifecycle
I'm trying to do something using a boolean in a Fragment class each time the Fragment is displayed. Example My app launches, opens the FirstFragment and the boolean for the first time is always true, then I have an if clause that checks its value: if (FirstTime) { FirstTime =...

Why does Android start a new activity when my last activity calls finish()?

android,android-lifecycle,activity-lifecycle
I ran into a strange problem today : I have 3 activites : A, B and C. A starts B then finishes. B starts C then finishes. C is the only one running. And guess what happens when I call finish() on C (I have an exit app button) ?...

Android Activity constructor

java,android,android-activity,constructor,android-lifecycle
I noticed that using the shortcut Alt + Insert and selecting the builders, it tries to create a constructor with each private property (cManager and mTextView). I remember I already created projects without it and worked correctly. The error happens when I run the application, following the full logcat and...

Are Application.ActivityLifecycleCallbacks synchronously called before the lifecycle methods in the Activity?

android,android-activity,android-lifecycle
I've inherited some nice looking code that uses Application.ActivityLifecycleCallbacks. We're using the onActivityResumed method to take users back to a login screen when their session has timed out. There's no documentation in the API docs about how this works. Do we get any guarantees about when these methods are called...

Android - How to detect the final Activity in the stack

android,android-activity,android-lifecycle,back-stack,android-task
I use the code below to check the final Fragment in an Activity to pop a dialog @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Check if there is only one fragment if (keyCode == KeyEvent.KEYCODE_BACK) { if (getSupportFragmentManager().getBackStackEntryCount() == 1) { DlgUniversalError.shallIQuit(this, getApplicationContext() .getResources().getString(R.string.doYouWantToQuit), getSupportFragmentManager()); return false; }...

While loop causes UI to go blank

android,android-activity,android-lifecycle
I'm writing a simple Whack a Mole clone, and I've got my UI elements declared in a GridLayout in a layout.xml, then assigned to ImageView variables in an array programmatically. I've got a startGame() method that simply takes a random int, pulls it from the array and causes it to...

Difference and uses of onCreate(), onCreateView() and onActivityCreated() in fragments

android,android-fragments,android-lifecycle,oncreate,fragment-lifecycle
What are the differences between onCreate(), onCreateView(), and onActivityCreated() in fragments and what would they each be used for?