android-lifecycle

How to send notification if the app is at the background in android?

风流意气都作罢 提交于 2019-12-11 14:16:40
问题 Currently I am working on bluetooth scan, that means I will keep scanning the device, if there is device nearby , I will show it on screen, however, if the app is at the background, I need to show notification to the user. And now my working logic is like this, there is a main class that fire the scan service, the scan service job is to return a list of scanned device. And the main class job is to display/ process the result. The code is like this: Service public class Detector extends

Even though onCreateView runs again, View does not properly reassemble after BACK press?

二次信任 提交于 2019-12-11 10:25:54
问题 My app is almost complete. In the second snippet of code below, you will see a while loop that is temporary. The purpose of this loop is to add ten table rows to my questionContainer (soon, I will replace this with an AsyncTask that acquires similar elements from an SQL db). I put a Log.v right in the while loop, to see when it runs. It turns out, on initial launch, the while loop and the onCreate View runs just fine. But after pressing back, then reopening the app via app switcher, while

Why native WLClient lifecycle bind to Activity lifecycle

蓝咒 提交于 2019-12-11 09:45:45
问题 Short Version I've found that WLClient lifecycle is bound to Activity. Activity lifecycle is managed by OS. Do you have any recommendations to compensate this? Long Version For Android Native project, the first step should be create a WLClient instance by the following call WLClient.getInstance(Context ctx) From the API document, it's a Context, not an Activity, but in reality, there would be a type cast in WLPush.java in WL framework. It doesn't make sense to bind a WLClient to a Activity,

Fragment in Fragment, onPause() called right after onResume()

↘锁芯ラ 提交于 2019-12-11 08:26:15
问题 in my app I have a single activity with a container layout for a fragment. In Activity's @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Logger.enable(); setContentView(R.layout.activity_main); FragLobby fragLobby = (FragLobby)getSupportFragmentManager().findFragmentByTag(FragLobby.debugTag); if(fragLobby==null) fragLobby = new FragLobby(); FragmentHelper.replaceSupportFragment(this, fragLobby, R.id.llMain, false, FragLobby.debugTag); /

[Android / Kotlin]: When are views initialized in lifecycle?

半世苍凉 提交于 2019-12-11 07:35:21
问题 I need to know the size of a Button (or any other view). But none of the procedures in lifecycle (onCreate, onStart, OnResume) seem to know it, as the Button seems not yet to be initialized! ... import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { private var servOffset: Int=0 // Value depends on Layout/Orientation and Device override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main

What can I expect when onCreate() calls startService()

穿精又带淫゛_ 提交于 2019-12-11 07:11:54
问题 I am trying to understand the Service Life Cycle while working through some Android Open Source Code. I was looking at a Service implementation which I distilled down to something like the following... public class MyService extends Service { public MyService() { super(); } @Override public void onCreate() { super.onCreate(); init(); //==this seems odd to me //comment in AOSP says startService() is called to make //sure Service stays around long enough for the async call //to complete.

ViewPagerIndicator.CirclePageIndicator crash in OnSaveInstanceState

老子叫甜甜 提交于 2019-12-11 04:15:58
问题 So I have this activity with a ViewPager and a CirclePageIndicator. The problem is that if I make a phone call from this page, the activity crashes in OnSaveInstanceState. The log contains the following message : System.MethodAccessException: Method '(wrapper dynamic-method) object:dynamic_callback_0 (intptr,intptr)' is inaccessible from method 'ViewPagerIndicator.CirclePageIndicator/SavedState:InitializeCreator ()' The page is quite simple : <?xml version="1.0" encoding="utf-8"?>

Update Activity data from service when its paused

六月ゝ 毕业季﹏ 提交于 2019-12-11 03:07:38
问题 Lets say I have an activity that has a data object. It updates its gui component based on that object. Now lets say that it is paused ( OnPause is called) but not stopped or destoryed Meanwhile , a push notification is received ( intentservice is started) and I need to update that object with the push notification object so I gui is updated when the app is resumed. I thought about sending a broadcast to the activity so it can update its dataobject But I read somewhere that when activity is

Reauthenticate on restart - Android

和自甴很熟 提交于 2019-12-11 02:19:29
问题 I need reauthenticate user credentials every time onRestart is called (usually this means the user has locked&unlocked the screen or put it on background and then returned to it). So I did that: @Override protected void onRestart() { super.onRestart(); Intent intent = new Intent(this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(LoginActivity.REAUTHENTICATE); startActivity(intent); } This works, the LoginActivity was shown, but when it finishes the

Passcode on resume from background

扶醉桌前 提交于 2019-12-11 02:04:02
问题 i have a question if there is decent way to handle this situation: i would like my app to launch passcode activity as soon as application is launched for very first time or then user resumes it from background (for example user clicks home button and moves application into background and then launches it again). I know i can do this using special permissions and granting access to system tasks, but i don't want to do this way. Also some of you will suggest to use onPause, onResume and onStop