android-lifecycle

Minimal android foreground service killed on high-end phone

孤者浪人 提交于 2019-11-29 20:42:43
I'm trying to create an app that lets users log routes (locations/GPS). To ensure locations are logged even when the screen is off, I have created a foreground service for the location logging. I store the locations in a Room Database which is injected into my service using Dagger2 . However, this service is killed by Android which is, of course, not good. I could subscribe to low memory warnings but that doesn't solve the underlying problem of my service getting killed after ~30 minutes on a modern high-end phone running Android 8.0 I have created a minimal project with only a "Hello world"

What the equivalent of activity life cycle in iOS?

北战南征 提交于 2019-11-29 19:19:28
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() This is a comparison between the lifecycle of Android vs iOS: Note : viewDidUnload is deprecated after iOS 6 来源: https://stackoverflow.com/questions/28969032/what-the-equivalent-of-activity-life-cycle-in-ios

DialogFragment displayed from onContextItemSelected doesn't survive onPause/onResume

一世执手 提交于 2019-11-29 19:05:11
问题 I have a DialogDragment which I can show one of two ways: 1) By tapping on a ListView item from its OnItemClickListener 2) By activating a the ListView's context menu and selecting a menu item Doing #1 works fine under all lifecycle events, but if I invoke it via #2 and I pause the activity (by going Home) and the resuming it via the task switcher, the dialog is no longer displayed. The fragment is there, and I can rotate the device and show the dialog. I experimented, and if I put the

Access to application class in Broadcast Receiver

眉间皱痕 提交于 2019-11-29 18:50:14
问题 I want to check internet connection in Broadcast Receiver; And set result (A boolean flag) to a global variable, to use it on whole application, in if conditions; That if internet is disconnected, set a status imageview in main activity, to red image, and if connected, set it to green. I followed this topic. But there is no getApplication() in Broadcast Receiver; And iI should use getApplicationContext() instead. On another side, this topic: when writing code in a broadcast receiver, which is

Can I start a new application but inside a “frame” I have created?

烈酒焚心 提交于 2019-11-29 16:24:05
Is it possible to from my application to start another (any other) application, but the new application to be displayed inside a "frame" I have created? Not generally. You cannot embed the UI of another app in your app. The primary exception to that is via app widgets, if you implement an AppWidgetHost . Is it possible to from my app to start another (any other) application but the new application to be displayed inside a frame I have created? Basically, not. When you start an application component registered within another application manifest file, a new process for this component will be

Which function is called when application is removed from task manager

这一生的挚爱 提交于 2019-11-29 16:19:57
I need to make status of user offline. When I press home button onStop() is called, that's fine. When I press back button onDestroy() is invoked. But when I close the app from recent apps by swiping it, onStop() or onDestroy() isn't called. I need to know when the app is closed from recent apps to do something (e.g make user offline). Make a service : public class MyService extends Service { private DefaultBinder mBinder; private AlarmManager alarmManager ; private PendingIntent alarmIntent; private void setAlarmIntent(PendingIntent alarmIntent){ this.alarmIntent=alarmIntent; } public void

onCreate() called while Activity is stopped (but not destroyed). Only after installation

核能气质少年 提交于 2019-11-29 15:15:47
问题 I'm working on an app that targets Api 19, and that is basically a Processing sketch. The problem I'm facing is that the first time my app is run, right after installing it, it works well until the user sends it to the background. Then, if they click on the app icon again, onCreate() is called but the activity is not destroyed or restarted. Some variables change and that produces strange behaviours. This happens ONLY the first time the app is used. After force closing it, this behaviour won't

Back and Nav Up have different results

耗尽温柔 提交于 2019-11-29 15:11:43
问题 I'm having an issue with activity navigation and I can't figure out what I'm doing wrong. I have a MainActivity and a SettingsActivity but using the Back and Up (on the action bar) have two different results from the Settings Activity. For example If I press the Back button I get the following lifecycle callbacks within the MainActivity : V/lifeCycle: onOptionsItemSelected V/lifeCycle: onPause V/lifeCycle: onSaveInstanceState-Bundle[..] V/lifeCycle: onStop << PRESS BACK BUTTON >> V/lifeCycle:

Android - Activity constructor

﹥>﹥吖頭↗ 提交于 2019-11-29 12:55:38
I noticed that using the shortcut Alt + Insert and selecting the builders, it tries to create a constructor with each private property (e.g. 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 the Activity constructor: Constructor with private property: private ConnectivityManager cManager; private TextView mTextView; public SplashScreenActivity() { this.cManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); this.mTextView = (TextView)this

Android; How can I initialise state in one activity, then have another refresh that?

只愿长相守 提交于 2019-11-29 11:57:39
I have two activities The first one gets some data from a content provider, and displays it The second activity has a button, and when clicked it should call the first activity to "refresh", in other words to reload data from the content provider This is my first activity ... @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contactsview); // Grab data and put it onto screen getDataAndPutToUI(); } @Override public void onStart() { //Refresh data getDataAndPutToUI(); } ... And this is my second activity @Override public void