Currently I'm trying to add a flutter app to my android app but when I try to do an Intent the app crashes and prints the following issue:
I followed this guide here
I get this error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testappandroid/io.flutter.embedding.android.FlutterActivity}: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException: ensureInitializationComplete must be called after startInitialization
at io.flutter.view.FlutterMain.ensureInitializationComplete(FlutterMain.java:168)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.initializeFlutter(FlutterActivityAndFragmentDelegate.java:177)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:140)
at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:399)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
So it says: ensureInitializationComplete must be called after startInitialization. One solution is to call FlutterMain.startInitialization(this) in the Flutter Activity. But this isn't working for me:
My Flutter Activity:
public class MainActivity extends FlutterActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
FlutterMain.startInitialization(this);
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
My android app AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.testappandroid">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="io.flutter.embedding.android.FlutterActivity"
android:theme="#style/AppTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<meta-data
android:name="io.flutter.Entrypoint"
android:value="main"
/>
</activity>
</application>
</manifest>
My flutter module AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testappflutter.host">
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="testappflutter"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
With this line of code I try to open the FlutterActivtiy. This is calling the main() function in my dart code:
Intent defaultFlutter = createDefaultIntent(activity);
activity.startActivity(defaultFlutter);
The code above should start this:
void main() => runApp(MaterialApp(
routes: {
"/": (context) => TestWidget()
}
));
So I followed step by step the guide for adding Flutter to an existing android app. Do I forget something? In my mind maybe the AndroidManifest of the flutter app needs some changes? Any ideas what I'm doing wrong?
insure that you import the right packages:
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
instead of
import io.flutter.app.FlutterActivity
in your MainActivity so your Main activity should look like this:
package com.example.example
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
class MainActivity: FlutterActivity() {
}
FlutterMain.startInitialization(this);
Add This Line Before Super.Create like
FlutterMain.startInitialization(this) //Added line
super.onCreate(savedInstanceState)
GeneratedPluginRegistrant.registerWith(this)
Despite the message ensureInitializationComplete must be called after startInitialization, it is not required to call it. Run Flutter activity this way:
FlutterMain.startInitialization(context)
startActivity(FlutterActivity.createDefaultIntent(context))
If you get the crash NoClassDefFoundError (class DefaultLifecycleObserver), add this dependency to your android module:
implementation 'android.arch.lifecycle:common-java8:1.1.0'
Related
I'm trying to create music app uses just_audio & just_audio_background plugins, App is working fine but I'm trying to integrate Stripe from flutter_stripe plugin. I get an exception when click on checkout button. its look like class com.ryanheise.audioservice.AudioServiceActivity from just_audio_background conflicting with flutter_stripe plugin
Exception
Your Main Activity class com.ryanheise.audioservice.AudioServiceActivity is not a subclass FlutterFragmentActivity.
MainActivity.kt
package com.example.spotify
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() {
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.spotify"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application
android:label="spotify"
android:name="${applicationName}"
android:icon="#mipmap/ic_launcher"
android:usesCleartextTraffic="true">
<activity
android:name="com.ryanheise.audioservice.AudioServiceActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<service android:name="com.ryanheise.audioservice.AudioService"
android:foregroundServiceType="mediaPlayback"
android:exported="true" tools:ignore="Instantiatable">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
<!-- ADD THIS "RECEIVER" element -->
<receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver"
android:exported="true" tools:ignore="Instantiatable">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
</application>
</manifest>
`
I tried custom activity defining directly into menifest but its not work. please help me I'm newbie
You can try AudioServiceFragmentActivity instead of AudioServiceActivity. More information about the different ways to define an audio service activity can be found in the audio_service documentation.
I am having this error
I/Ads (21352): Starting ad request.
I/Ads (21352): SDK version: afma-sdk-a-v15090040.14300000.1
I/Ads (21352): This request is sent from a test device.
W/Ads (21352): Could not find com.google.android.gms.ads.AdActivity, please make sure it is declared in AndroidManifest.xml.
W/Ads (21352): Missing AdActivity with android:configChanges in AndroidManifest.xml. You must have the following declaration within the <application> element: <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
D/skia (21352): Program linking failed.
D/skia (21352): Program linking failed.
I tried to resolve the issue as per mentioned in this missing-adactivity-with-android-configchanges and AdView - Missing adActivity with android:configChanges in AndroidManifest.xml but it having same issue.
in profile/AndroidManifest I have
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="puns.jokes.org.jokespuns">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
in main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="puns.jokes.org.jokespuns">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Jokes and Puns"
android:icon="#mipmap/ic_launcher">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-<app-id>"/>
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
What I am doing wrong here?
I was receiving the same error.
My solution to this problem was to update in the grandle build at the application level.
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.google.gms: google-services: 4.2.0'
My AndroidManifest:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-***********~**********"/>
I hope it helps. regards
E/AndroidRuntime: FATAL EXCEPTION: main Process: de.mywoofi.app, PID: 17970 java.lang.RuntimeException: Unable to instantiate application de.mywoofi.app.MyWoofiApplication_: java.lang.ClassCastException: de.mywoofi.app.MyWoofiApplication_ cannot be cast to android.app.Application at android.app.LoadedApk.makeApplication(LoadedApk.java:1069) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842) at android.app.ActivityThread.access$1100(ActivityThread.java:199) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.ClassCastException: de.mywoofi.app.MyWoofiApplication_ cannot be cast to android.app.Application at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:50) at android.support.v4.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:49) at android.app.Instrumentation.newApplication(Instrumentation.java:1120) at android.app.LoadedApk.makeApplication(LoadedApk.java:1061) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5842) at android.app.ActivityThread.access$1100(ActivityThread.java:199) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
The Problem is, that I have no idea, what the exact solution is.
I've tried a lot of "solutions" from this page, but maybe I'm to stupid to resolve that problem.
If there are any request for some Code, please ask.
Thanks for your help!
The requested Class (shortened)
#EActivity(de.mywoofi.app.R.layout.activity_main)
public class MyWoofiApplication extends Activity
{ [...]
}
And the cast:
<application
android:name=".MyWoofiApplication_"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
tools:replace="android:icon"
android:fullBackupContent="true"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity
android:name=".ui.activity.SplashActivity_"
android:label="#string/app_name"
android:theme="#style/AppTheme.Full"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
My updated Manifest
<application
android:name=".ApplicationClass"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
tools:replace="android:icon"
android:fullBackupContent="true"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity
android:name=".ui.activity.SplashActivity_"
android:label="#string/app_name"
android:theme="#style/AppTheme.Full"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
here my ApplicationClass.java
public class ApplicationClass extends Application{
#Override
public void onCreate(){
super.onCreate();
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
}
}
Application need to extends Application and mentioned in Manifest file
& MainActivity extends Activity
You got error because your MyWoofiApplication_ is not extend Application it's extend Activity so got that's why you got this error:
de.mywoofi.app.MyWoofiApplication_ cannot be cast to android.app.Application
Application Class
public class ApplicationClass extends Application {
#Override
public void onCreate() {
super.onCreate();
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
}
}
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="YOUR_PACKAGE_NAME">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".ApplicationClass"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize" />
</application>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
setContentView(R.layout.activity_main);
}
}
Hope you understand now and it may help to you.
In android name - In Manifest.xml, you have this MyWoofiApplication_ but you need only this MyWoofiApplication am I right?
you have this line in manifest:
<application
android:name=".MyWoofiApplication_"
so MyWoofiApplication_ should extends android.app.Application but it did not so you have this exception:
de.mywoofi.app.MyWoofiApplication_ cannot be cast to android.app.Application
MyWoofiApplication_ is extending Activity so you can not cast it to Application.
You can remove android:name=".MyWoofiApplication_" from your application tag to resolve your issue.
Trying to connect FB Auth to Firebase. Appears error
FATAL EXCEPTION: main
Process: com.borisruzanov.social, PID: 20684
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.borisruzanov.social/com.borisruzanov.social.FacebookLoginActivity}: A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:276)
at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:232)
at com.borisruzanov.social.FacebookLoginActivity.onCreate(FacebookLoginActivity.java:49)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618
Here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.borisruzanov.social">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".AuthPage">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GoogleSignInActivity" >
</activity>
<activity android:name=".PhoneAuthActivity" >
</activity>
<activity android:name=".FacebookLoginActivity"
>
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
</activity>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application>
</manifest>
And also i dont understand why initialization of SDK is not actual and it stroked. I have tried solutions which on stack. Doesn't help.
Also if any1 know the good example where Firebase and Facebook auth integrated well? Because as always firebase guide is totally collapsed my brain.
You need add
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//initialize Facebook SDK
FacebookSdk.sdkInitialize(getApplicationContext());
if (BuildConfig.DEBUG) {
FacebookSdk.setIsDebugEnabled(true);
FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
}
setContentView(R.layout.activity_main); }
Need add meta-data to Application
<application android:label = "#string/app_name" ... >
...
<meta-data android:name = "com.facebook.sdk.ApplicationId" android:value = "#string/facebook_app_id" />
...
</ application>
instead of
<activity android:name=".FacebookLoginActivity"
>
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
</activity>
You don't really need to initialize FacebookSDK manually as it gets initialized automatically, just change your manifest file as #Boris showed. Hope it will work now.
I am trying to implement the BluetoothLeGatt Example Project from android into my own app to handle the BLE Services.
BluetoothLeGatt Example Android
The actual state is that i have my own app which has only one activity and i am switching between the other pages with fragments. I would like to implement the android example so i can receive Bluetooth data and save it into a own data class (via an Interface or something like that not sure right now).
The Bluetooth Example is working without any Problems if i am running it on my device. I can also implement the example into my app and use it as "start activity" with the following manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bb.app">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:debuggable="true">
<activity
android:name=".DeviceScanActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name">
<!--android:theme="#style/AppTheme.NoActionBar"-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DeviceControlActivity"/>
<activity android:name=".MyActivity"/>
<service android:name=".BluetoothLeService" android:enabled="true"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
But i am not able to Switch between the example activity and my own. I am using a simple Button with a onClickListener to Switch it like that:
buttonChangeActivity = (Button) findViewById(R.id.buttonChangeActivity);
buttonChangeActivity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(DeviceControlActivity.this, "PRESSED", Toast.LENGTH_SHORT).show();
try{
Intent myIntent = new Intent(DeviceControlActivity.this, MyActivity.class);
DeviceControlActivity.this.startActivity(myIntent);
}catch (Exception e){
Toast.makeText(DeviceControlActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
}
}
});
And it is still working. But then it says that the MyActivity class Needs to use the Theme.AppCompat but i am already using it. Here is the whole error code:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bb.app/com.example.bb.app.MyActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5258)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:343)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.bb.app.MyActivity.onCreate(MyActivity.java:262)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
I am using a toolbar in my activity and the example Project uses an actionbar so i am pretty sure i Need to "Switch" between the themes while my Project is running but i don't know how to. I've already read some other cases about this behavior:
Stackoverflow 1
Any advice how to Switch the themes while the Project is running or where to Change it in my Android Studio?
Ok needed only few more minutes and i've fixed my own issue.
Just changed the manifest like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bb.app">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar"
android:debuggable="true">
<activity
android:name=".MyActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name">
<!--android:theme="#style/AppTheme.NoActionBar"-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DeviceControlActivity"
android:theme="#android:style/Theme.Holo.Light"/>
<activity android:name=".DeviceScanActivity"
android:theme="#android:style/Theme.Holo.Light"/>
<service android:name=".BluetoothLeService" android:enabled="true"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
So changing the theme for each activity, thanks anyways.