android-lifecycle

Best way to implement Socket.io in android

余生长醉 提交于 2019-11-28 17:12:51
问题 I am planning to implement Socket.io in android by this library for a chat based application. As far as I understood the library seems to be pretty good. I want to know how to maintain a single socket connection throughout the app all the time? Here I have listed out ways to achieve, in which I need the best and stable way. Three ways MainApplication Class extends Application By this we have a good scope that the socket connection is maintained in the main thread ( or application's life cycle

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

DialogFragment - retaining listener after screen rotation

人盡茶涼 提交于 2019-11-28 16:42:31
I have a DialogFragment which creates a DatePickerDialog. I'm using a static method called newInstance to set the initial values in order to use the default empty constructor. However, how am I supposed to set the listener? After the screen rotation, when clicking in the "Done" button, the listener doesn't do anything since it does not exist. public class DatePickerFragment extends DialogFragment { public static final String ARG_YEAR = "year"; public static final String ARG_MONTH = "month"; public static final String ARG_DAY = "day"; private OnDateSetListener listener_; public static

Android how to stop refreshing Fragments on tab change

☆樱花仙子☆ 提交于 2019-11-28 16:41:34
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 android.os.StrictMode; import android.support.v4.app.FragmentActivity; import

Minimal android foreground service killed on high-end phone

霸气de小男生 提交于 2019-11-28 16:19:18
问题 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

Android - How to tell when a specific view has been rendered?

半世苍凉 提交于 2019-11-28 14:32:15
I have a regular button that I want to display a timer on. So imagine the text of the button changes every second as a countdown timer. However, I need this timer to only start when the button is fully rendered and ready to go on the screen. Right now I'm starting the timer (which is an AsyncTask ) in the onCreateView() of a fragment. This isn't that accurate, because I do some other loading stuff that I have to have. I could potentially move the timer start at the bottom of onCreateView() but even that isn't very accurate either. I saw that there's a OnGlobalLayoutListener tree observer. But

What the equivalent of activity life cycle in iOS?

空扰寡人 提交于 2019-11-28 13:40:29
问题 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() 回答1: 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

Forcing Android to not redraw activity on orientation change

南笙酒味 提交于 2019-11-28 13:03:32
I have been going gaga to figure this out. Although I have read a lot that on Orientation Change, Android kills an activity and starts it as a fresh one, and the only way to handle this is to save all the stuff inside onSaveInstanceState() and try to restore it inside onCreate() . But my activity does a lot and different kind of network activities at different times and if the orientation is changed when the network activity is being performed, I'll have to handle a lot of different and complex scenarios. Is there any simple way to just point Android that this activity doesn't need to be

Activity Transition Animations in Android

对着背影说爱祢 提交于 2019-11-28 12:34:22
I want to apply an activities transition like the one that HTC phones have: When you start a new Activity there is a slide right-to-left, but when you press the back button to return to the previous Activity, there is a slide left-to-right animation. I have used overridePendingTransition in the onResume of my Activities to simulate the slide right to left animation, but when I press the back button, the same animation is executed which is wrong (from a result perspective). Thus I would like to ask how to manage having different animations for an Activity, one for when it is created, and one

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

随声附和 提交于 2019-11-28 10:03:49
问题 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? 回答1: 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 . 回答2: 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