oncreate

Can I use setContentView outside the oncreate method?

旧街凉风 提交于 2019-12-09 16:26:38
问题 I have seen many people telling that you can set setContentView outside the oncreate method, but I didn't find anywhere an example. Now when I try to use setContentView, my app just crashes. Here is my source code: AlarmActivity.java: package com.alarm.example; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.RelativeLayout; public class AlarmActivity extends

Android SDK equivlent for viewWillAppear (iOS)?

假装没事ソ 提交于 2019-12-09 15:27:28
问题 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

Android: Stop Recreating the activity on orientation change

五迷三道 提交于 2019-12-08 16:05:50
问题 I have a listview with two buttons in my main.xml layout. On click of one button i'am creating a textview dynamically and adding it at the bottom of the screen to confirm the user interaction. When the user clicks 2nd button (Confirm button), i need to add that text to listview. To support landscape mode, i have the same layout file in layout-land folder. When i click on 1st button it is creating a textview with some text and adding at bottom of the screen. Now if a change the device

SQLiteOpenHelper not calling onCreate

蓝咒 提交于 2019-12-07 20:26:42
问题 This is the fist time I've used SQLiteOpenHelper (or databases on android). When I get a writeable database I was wondering why onCreate isnt being called on each new instance of the class. Am I doing something wrong? public class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "MyDatabase.db"; private static final int DATABASE_VERSION = 1; private String PrSQLcmd = ""; public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE

Why is my onCreateView method being called twice?

久未见 提交于 2019-12-07 09:56:49
问题 While debugging another issue, I realized that the onCreateView method of one of my activities was being called twice. I'm new to programming and I don't fully understand how android calls these methods when the activity loads, but it doesn't seem right to me that it would be called twice. Eliminating most of my code, I still see my System.out message twice. public class AddCourse extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate

Error: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

喜你入骨 提交于 2019-12-06 20:24:23
问题 I got a problem with my android app. I got a button and and event associated , but when I click the first time an error appears "spans cannot have zero lenght". . But when I click the second time, the event onclick runs well.. look at my java code: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button selectAltitude = (Button) findViewById(R.id

Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容

谁说胖子不能爱 提交于 2019-12-06 17:36:10
1.在应用中固定屏幕方向。 在AndroidManifest.xml的activity中加入: android:screenOrientation=”landscape” 属性即可(landscape是横向,portrait是纵向)。 OK 2.随屏幕旋转时,不重新调用onCreate。 当将手机屏幕旋转时, 系统会 被强制重置启动onCreate 方法 。 1)修改AndroidManifest.xml 在activity属性中加入: android:configChanges=”orientation|keyboardHidden” android:configChanges ,这个方法主要是负责列出清单,当清单上用户指定的设置改变时,Activity会自己处理这些变化。 orientation ,屏幕界面旋转(可能是用户手动旋转的),【注意:如果你的开发API等级等于或高于13,你还需要设置screenSize,因为screenSize会在屏幕旋转时改变】 keyboardHidden ,键盘辅助功能改变 2) 在相对应的Activity中继承重写onConfigurationChanged方法,这个方法将会在我们的应用发生变化时,让我们能随心所谓地进行监听处理。 public void onConfigurationChanged(Configuration

IMvxAppStart related crash with Application.OnCreate overridden

点点圈 提交于 2019-12-06 15:38:34
问题 The error: MvvmCross.Exceptions.MvxIoCResolveException : Failed to resolve type MvvmCross.ViewModels.IMvxAppStart occurred when tried to override Application.OnCreate [Application] public class RemoteApplication : MvxAndroidApplication<Setup, Core.App> { public RemoteApplication(IntPtr reference, JniHandleOwnership transfer) : base(reference, transfer) { } public override void OnCreate() { base.OnCreate(); } } 回答1: It was fixed by @Martijn00 advice from Similar Question public override void

Android onCreate Service called when Activity onDestroy called

≡放荡痞女 提交于 2019-12-05 17:26:40
I have an activity that starts a service. If I exit to home screen and then from the recent apps list manually close the activity, onCreate is called again in the service. So when the activity is destroyed, onCreate is called again (even though the service was running at the time onDestroy was called in the activity) I don't want onCreate in the service to be called again. I know its a possible duplication of this: Android service onCreate is called multiple times without calling onDestroy BUT the solution suggested here of putting the service in another process doesn't work (at least on

Why is my onCreateView method being called twice?

安稳与你 提交于 2019-12-05 16:35:43
While debugging another issue, I realized that the onCreateView method of one of my activities was being called twice. I'm new to programming and I don't fully understand how android calls these methods when the activity loads, but it doesn't seem right to me that it would be called twice. Eliminating most of my code, I still see my System.out message twice. public class AddCourse extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_course); if (savedInstanceState == null) {