How to use AndroidBootstrap without extends Application - android

I am trying to use Android Bootstrap library. I followed Quick Start. In Quick Start, it says I should override my class like this:
public class SampleApplication extends Application {
#Override public void onCreate() {
super.onCreate();
TypefaceProvider.registerDefaultIconSets();
}
}
How can I use this library without extending Application class? I want to use this library in my Activity classes.
LoginActivity:
public class Login extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TypefaceProvider.registerDefaultIconSets();
setContentView(R.layout.activity_login);
}
}
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.merve.tev.Login">
<com.beardedhen.androidbootstrap.BootstrapDropDown
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:bootstrapText="Medium {fa_thumbs_o_up}"
app:bootstrapBrand="regular"
app:roundedCorners="true"
app:bootstrapSize="md"
app:dropdownResource="#array/bootstrap_dropdown_example_data"
app:bootstrapExpandDirection="down"
tools:layout_editor_absoluteY="202dp"
tools:layout_editor_absoluteX="115dp" />
</LinearLayout>
In my MainActivity class, I placed the button. When I click it, I should go LoginActivity class. However, I get an error:
java.lang.RuntimeException: Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.beardedhen.androidbootstrap.BootstrapDropDown

In your activity class:
In onCreate() Method, write this line before setContentView();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TypefaceProvider.registerDefaultIconSets();
}
I hope it will work.

It's recommended to invoke TypefaceProvider.registerDefaultIconSets(); in your application class because that will load the FontAwesome typeface, before any views are displayed on screen.
If you're not loading FontAwesome icons then you can skip this step. If you're worried about startup time then you could try performing it asynchronously.
Finally, if you know for a fact that your app will always launch from a certain activity, then you can call TypefaceProvider.registerDefaultIconSets(); before setContentView is called, and should still be able to use FontAwesome icons.
The only tradeoff here is that most apps have multiple Activities which act as entry points, meaning you might have to add this setup logic to multiple places. That's why the current advice is to set it up in your Application class - you'll only ever need to initialise it once.

Related

Implementing launch screen for android with Delphi/Firemonkey

reading the https://developer.android.com/topic/performance/vitals/launch-time about the right way to implement a launch screen they say to create a Launcher style
<activity ...
android:theme="#style/AppTheme.Launcher" />
and they say that the easiest way to transition back to your normal theme is to call setTheme(R.style.AppTheme) before calling super.onCreate() and setContentView():
KOTLIN
JAVA
public class MyMainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// Make sure this is before calling super.onCreate
setTheme(R.style.Theme_MyApp);
super.onCreate(savedInstanceState);
// ...
}
}
problem is with delphi, when/where can I call setTheme(R.style.Theme_MyApp); ? from inside the form create it's not work so seam already too late, and even just after Application.Initialize it's seam to not work either :(

It is not working, and Right place to implement onSaveInstanceStance()

I am trying to grasp the concept of life cycle call back methods of an activity and what happens inside them.
I am writing a small activity class which just displays a text.
The Problem is that the activity starts to display and i get a dialog saying "unfortunately Activity Lifecycle and Coordination has stopped working"
Please tell me how to fix this.
The code is as follows:-
package com.practice.lifecycle_coordination;
//import android.app.ActionBar;
import android.app.Activity;
//import android.os.Build;
import android.os.Bundle;
class MainActivity extends Activity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
protected void onStart(){
super.onStart();
}
protected void onResume(){
super.onResume();
}
protected void onPause(){
super.onPause();
}
protected void onStop(){
super.onStop();
}
public void onSaveInstanceState(Bundle savedInstanceState){
super.onSaveInstanceState(savedInstanceState);
}
}
LAYOUT FILE:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+string/title"
android:gravity="center_horizontal"
android:textStyle="bold" />
</LinearLayout>
STRINGS RESOURCE FILE:-
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Activity LifeCycle</string>
<string name="action_settings">Settings</string>
<string name="title">MAIN ACTIVITY</string>
</resources>
Is onSaveInstanceState() implemented at the right place? In case I want to save some additional data into the bundle, is this the right place to implement it?
I know that I don't need to write any life cycle call back methods except onCreate(). But I just wanted to check.
You don't have to write onCreate() actually. The only life cycle methods you have to write are ones in which you need to override and implement your own code within. onCreate() is overwritten in virtually every Activity, however, because you typically are going to want to use this point in the life cycle to initialize variables etc.
As for Is onSaveInstanceState() implemented at the right place?
Yes. The order within your Activity in which your life cycle methods occur doesn't matter in the slightest. As long as you're in the right activity, you're fine. These methods are called automatically as your activity goes through those life cycle stages.
As for what's actually wrong with the current code? We'll need a lot more information. Your logcat will give you some information on what actually caused the crash. Post that, and your problem can be better diagnosed.

android programmatically using shape

I am trying to run MainActivity which extends View but its not running. Do i have to use MainActivity extends Activity to run the application because i want to use draw() method in MainActivity class.Can i use it directly or i have to use View instead of activity?.
Here is my code
public class MainActivity extends View {
public MainActivity(Context context) {
super(context);
}
Main.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
Yes your main activity (and any other) MUST extend Activity.
If you want to make your own, custom control, just write it (extend view or some of it's descendatns) and put it into your main layout as any other control.
In your custom control you can override onDraw() method if you want.
Take a look at the docs:
Custom controls
Try something like:
class MyActivity extends Activity {
...
#Override
protected void onCreate {
...
setContentView(R.layout.main);
....
}
}
After you setContentView, you can reference it by calling findViewById(<LinearLayout's id>). In your layout you can place the view that you want to do the drawing
Your activity should extend Actvity and you have get your draw image as view which is a object of class that extends View
I hope this will be usefull to you.

Using GlSurfaceview in activity

I have an Activity and i had set activity's content view as "R.layout.main.xml".And i have an another class which contains animation created using openGL. Now i need to use this animation in the background of the Activity.
The code is like this
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_pixie);
mGLView = new ClearGLSurfaceView(this);
setContentView(mGLView);
}
But my app is Crashing ..How can i solve this.
When you call the setContentView() a second time, you replace what had been set the first time, leaving you with only the background. The crash is most likely because you depend on the elements in the main layout, which is removed.
Rather than calling setContentView() twice, you should include the GLSurfaceView in the main layout. Below is an example of how this can be done:
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent>
<your.application.package.ClearGLSurfaceView
android:layout_width="match_parent"
android:layout_width="match_parent"/>
<!--put the rest of your layout here, i.e the contents of the original R.layout.main_pixie-->
</FrameLayout>
Then you can load this layout in your onCreate() as usual (main_pixie_new refers to the above xml, I just gave it that name to keep things as clear as possible):
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_pixie_new);
}

Simple activity switch not working. No Errors

I have a basic calculator app I'm making. Two activities, the main one and ResultView.
I've made it where I click a button on activity A to go to activity B. The log says activity B is started and "displayed" successfully, the title for the new activity loads, but the body does NOT show. I added a simple Text view with static text.. see the result.xml at the bottom. I also tried inserting information programmatically, but that didn't do.
When I debug the program, I tried putting breakpoints as the activity is called with startActivity() as well as on the first line of the onCreate method within the ResultView class (my activity "B") but the program never hits the second breakpoint. In fact, it looks as if Looper.class is called in the end.
This bit of code is placed in the button handler on acitivity A:
i.putExtra("test1",34);
i.putExtra("test2",35);
this.startActivity(i);
This in the onCreate function in activity B:
public void OnCreate(Bundle
savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
}
The activity is in the manifest, within the "application" tag:
<activity
android:name="ResultView"></activity>
If I didn't supply enough info, let me know.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llParent"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="HELLO WORLD"
/> </LinearLayout>
If more info is needed, let me know...in short, "HELLO WORLD" does not display at all.
It's not OnCreate, it's onCreate (lowercase o). Otherwise the method won't be overriden. The #override annotation has no effect if it's omitted, it's just for readability for the programmer.
Are you sure that the public void line or the line before that contains #Override? If not, you're not overriding the OnCreate method. The code should read
#Override public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
}
EDIT
Of course the "O" must not be a capital "O"...

Categories

Resources