oncreate

Set Full Screen out onCreate

浪尽此生 提交于 2019-12-04 03:08:59
问题 I can only set my Activity to Full Screen in onCreate method (before setContentView)? Is there any way I can set to full screen outside of onCreate? Thanks 回答1: Is possible! Adding this code. // go full screen WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes(); attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; mActivity.getWindow().setAttributes(attrs); // go non-full screen WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes(); attrs.flags &=

Android SDK equivlent for viewWillAppear (iOS)?

我怕爱的太早我们不能终老 提交于 2019-12-04 02:19:54
Situation I have a fairly simple app with 2 "layouts" using SharedPreferences. Main.xml Settings.xml Main has a textView that uses getString from SharedPreferences. Also a button to open Settings. Settings has a spinner and a button to save to SharedPreferences. The textView gets updated when the App loads as I am calling setText() inside onCreate(Bundle savedInstanceState) Problem When I open Settings and update the SharedPreferences, I use the Back button to get back to Main. Since I am calling setText() inside onCreate() the textView does not update again until I exit the app and open the

Android: onCreate() getting called multiple times (and not by me)

寵の児 提交于 2019-12-04 01:51:46
There is something I don't quite understand right now. My main activity class creates a Service, which creates a new thread that waits for a TCP connection. Once one comes in, it will start a new activity: Intent dialogIntent = new Intent(getBaseContext(), VoIPCall.class); dialogIntent.putExtra("inetAddress", clientSocket.getInetAddress()); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); After that, the onCreate() method of that class gets run. It will create 2 threads: one records and send data, the other one receive and plays data. Those

Why do OnCreate should be called only once on the start of Activity?

只愿长相守 提交于 2019-12-03 14:43:56
I would like to know, why OnCreate() is called only once at the start of an activity? Can we call OnCreate() more than once in the same activity? If yes, than how can we call it? can anyone give an example? Thanks a lot!!! Why would you want to called it again? unless the activity is reconstructed, which is called by system. You cannot call OnCreate manually , it is the same reason why you won't call setContentView() twice. as docs: onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource defining your UI,

Can you please explain onCreate and Bundles?

怎甘沉沦 提交于 2019-12-03 14:20:49
I have been looking it up and I just cant seem to wrap myself around the onCreate and Bundles. I understand that the onCreate is called when the program starts but its how the Bundles get passed around and how they are pertinent. Can anyone try to put this into plain english because I cant seem to find it well described. Thanks Macarse The Bundle in the onCreate method should hold the state of you activity before it was killed. Simple example, when you change the orientation of your device your activity is recreated. Imagine the user is filling a long form and he/she accidentally changes the

Set text of spinner before item is selected

一世执手 提交于 2019-12-03 13:00:50
I have a spinner with three items and I use an XML string-array resource to feed it. When you open an activity the spinner normally shows the first item that's in the array list. I'd like to change that and show the text "Select one" in the spinner, before an item is selected. How can I do that? You can do that one of two ways. 1) Add "Select One" as the first item in your xml and code your listener to ignore that as a selection. 2) Create a custom adapter to insert it as the first line, EDIT In your resources <string-array name="listarray"> <item>Select One</item> <item>Item One</item> <item

requestFeature() must be called before adding content error on super.onCreate

风格不统一 提交于 2019-12-03 04:23:56
I have an abstract class extending ActionBarActivity . In the onCreate , I have: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); ... } The app crashes due to the requestFeature() before content error, specifically on the line super.onCreate(savedInstanceState) . After reading some of the similar posts, I came up with this solution: @Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate

Image on start up / loading

泪湿孤枕 提交于 2019-12-03 03:03:34
I ma developing an app, which at the moment when it is loading from the onCreate point, I just have a black screen (until the app gets its footing). Looking at other apps they have a company logo or cool image that pops up for a few seconds, can someone tell me how to do this please? And if you can set it to display for a minimal time? Create a new activity that displays the image for a few seconds and redirects to your main activity: public class SplashActivity extends Activity { private static final long DELAY = 3000; private boolean scheduled = false; private Timer splashTimer; @Override

android what to use instead of onRestart() in a fragment

北慕城南 提交于 2019-12-02 08:40:01
问题 I'm dealing with .setVisibility() of a view , inside my main fragment at app start. So what I want is that the view is invisible on app start (for this i set INVISIBLE inside onCreateView) and to be visible when I come back to my fragment from other activities while the app is open (and for this I tried to use onRestart() to set view VISIBLE but it cannot resolve onRestart method) is onRestart deprecated or? thanks EDIT: for all the answers below suggesting to use an onResume (and whom gave a

Load Data setOnItemSelectedListener

时间秒杀一切 提交于 2019-12-02 07:32:15
Problem: I load my class, the setOnItemSelectedListener function runs and sets variable wattage to a specific value, depending on what item was selected in the spinner. How can I prevent this from happening, how can I include a custom value for a variable wattage? Detail: I have a class called edit lighting. In this class all I want to do is load the data from the database. Currently when the light type spinner is selected, I associate a value with it. e.g. I pick CFL - wattage is then 26. But I let the user add a custom wattage in an edit text field. My problem is, when loading the data in