App is crashing on restart of app after tablet/mobile orientation change,
I m going to develop an application in landscape mode only, and I have made a layout in layout-land with name acitivty_main and there is no any portrait layout in my application and no any layout folder as well, I have also added screenOrientation="landscape" in manifest activity.
Activity Code Following:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
Manifest.xml code following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yasir.sample">
<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=".MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Project Structure:
FATAL EXCEPTION: main
Process: com.example.yasir.sample, PID: 12611
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.yasir.sample/com.example.yasir.sample.MainActivity}:
android.content.res.Resources$NotFoundException: Resource ID #0x7f04001b
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3151)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5205)
at android.app.ActivityThread.access$1100(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1741)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04001b
at android.content.res.Resources.getValue(Resources.java:2495)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:4236)
at android.content.res.Resources.getLayout(Resources.java:2311)
at android.view.LayoutInflater.inflate(LayoutInflater.java:413)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.yasir.sample.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6609)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3104)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3261)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5205)
at android.app.ActivityThread.access$1100(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1741)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Resources$NotFoundException
This exception is thrown by the resource APIs when a requested
resource can not be found
FYI
Remove
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Add android:configChanges="orientation|screenLayout" in Manifest section .
Finally
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout">
Then Clean and Rebuild your project .
https://androidresearch.wordpress.com/2013/05/10/dealing-with-asynctask-and-screen-orientation/
This link will explain how to prevent crashes from AsyncTask and Screen Orentation
Related
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.
This question already has answers here:
FirebaseApp.initializeApp(Context); Android error;
(3 answers)
Closed 5 years ago.
In my android app, i used firebase to sign in with google, but can't set the login activity before main.
Here's the stack trace:
02-12 23:57:02.524 8692-8692/bf_d.binary_femaledefense E/AndroidRuntime: FATAL EXCEPTION: main
Process: bf_d.binary_femaledefense, PID: 8692
java.lang.RuntimeException: Unable to start activity ComponentInfo{bf_d.binary_femaledefense/bf_d.binary_femaledefense.login}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process bf_d.binary_femaledefense. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process bf_d.binary_femaledefense. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source:54)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:0)
at bf_d.binary_femaledefense.login.onCreate(login.java:53)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
l already called the FirebaseAuth.initializeApp(this) in the onCreate method. But still showing initializing error in FirebaseApp.
Here's the library i used:
implementation 'com.google.android.gms:play-services-auth:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
And here is my AndroidManifest:
<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=".login"
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=".MainActivity"/>
<activity
android:name=".ContactSetup"
android:parentActivityName=".ContextSetup" />
<activity
android:name=".EditContacts"
android:parentActivityName=".EditContacts" />
<activity
android:name=".HowTo"
android:parentActivityName=".MainActivity" />
<activity
android:name=".AboutDevs"
android:parentActivityName=".MainActivity" />
<activity
android:name=".RecordHistory"
android:parentActivityName=".MainActivity" />
<activity
android:name=".CustomText"
android:parentActivityName=".ContextSetup" />
<activity
android:name=".ContextSetup"
android:parentActivityName=".MainActivity" />
</application>
Any Suggestions would be appreciated :)
Extend Application class and call FirebaseApp.initializeApp(this) in onCreate() method of that class:
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
}
And add android:name attribute to your manifest
<application
android:name=". MyApplication"
...
>
i made a new activity and when i im trying to move between them by clicking a button the app crash and logcat shows the error below
12-16 14:02:09.016 23235-23235/com.modather.scalculate E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.modather.scalculate, PID: 23235
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.modather.scalculate/android.support.v7.widget.AppCompatButton}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java)
at android.app.Instrumentation.execStartActivity(Instrumentation.java)
at android.app.Activity.startActivityForResult(Activity.java)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
at android.app.Activity.startActivity(Activity.java)
at android.app.Activity.startActivity(Activity.java)
at com.modather.scalculate.HomePage$onCreate$1.onClick(HomePage.kt:36)
at android.view.View.performClick(View.java)
at android.view.View$PerformClick.run(View.java)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<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=".HomePage"
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="com.modather.scalculate.age"
android:label="Calculate my age(SC)" />
</application>
i had searched over stackoverflow and found some solution but it didn't work for me.. so if it possible to fix mine ?
Here's the moving code
fab.setOnClickListener {
val intent = Intent(this, activity_age::class.java)
startActivity(intent)
}
There is Typing mistake check it
your activity name is activity_age and you have added in manifest age is
fab.setOnClickListener {
val intent = Intent(this,age::class.java)
startActivity(intent)
}
I'm developing an App that can be Screen Pinned aka Corporate Owned Single Use aka Lock Task Mode.
If I pin it and then:
I close it (killing it) and then I launch it again
or after some code modification in android studio and then perform Run
restart after pin and unpin
I get the following error:
[homtom-ht3_pro-0123456789ABCDEF]: E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xx.yyy, PID: 7928
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.yyy/com.xx.yyy.activities.LauncherActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xx.yyy/com.xx.yy.activities.StartActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5643)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xx.yyy/com.xx.yyy.activities.StartActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1788)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3809)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:3760)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4090)
at android.app.Activity.startActivity(Activity.java:4058)
at com.xx.yyy.activities.LauncherActivity.onCreate(LauncherActivity.java:16)
at android.app.Activity.performCreate(Activity.java:6099)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5643)
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:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
This is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xx.yyy">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<receiver
android:name=".receivers.DeviceAdminReceiver"
android:description="#string/app_name"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin_receiver" />
<intent-filter>
<action android:name="android.intent.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.intent.action.PROFILE_PROVISIONING_COMPLETE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".activities.LauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.StartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
If I don't ever pin the app I can restart/upgrade&run it many times I want.
The nice thing is that is not even possible to uninstall the app because it has been configured as Device Owner, and so, it cannot be uninstalled unless a factory reset.
I dont understand how is possible that my activity disappears after an app restart. Can be something related to the intent category or action?
If anyone else encountered this behavior can tell me I will submit an issue to the bug report site.
Thanks.
EDIT 18/3
I think maybe this is happening because at a certain point, I kill the home category activity that in my case is the missing StartActivity in question, and it is not restarted even if I restart the app.
Found the solution in my COSU disable pinning implementation, I was doing:
PackageManager mPackageManager = getApplicationContext().getPackageManager();;
mPackageManager.setComponentEnabledSetting(
new ComponentName(getApplicationContext(), StartActivity.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
to disable the pinning on device boot, but this actually disable the specified component.
The correct implementation would be:
PackageManager mPackageManager = getApplicationContext().getPackageManager();;
mPackageManager.setComponentEnabledSetting(
new ComponentName(getApplicationContext(), StartActivity.class),
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
PackageManager.DONT_KILL_APP);
I know that there are problems like this before. I have tried some of the solution given from the thread but it did not seem to solve the error for my application
This is my android.manifest file for the second activity
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RevGPAActivity"
android:label="#string/title_activity_rev_gpa">
<intent-filter>
<action android:name="com.example.user.testapp.RevGPAActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
And here is my MainActivity
private GoogleApiClient client;
Button start_rev_gpa;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
//Start Rev GPA
startRevGPA();
}
public void startRevGPA(){
start_rev_gpa = (Button)findViewById(R.id.startRevGPA);
start_rev_gpa.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.user.testapp.RevGPAActivity");
startActivity(intent);
}
}
);
}
I did not do anything on the xml file like android:onClick or anything. The app hangs for about 3 seconds then it stopped working
Logcat
FATAL EXCEPTION: main
Process: com.example.user.testapp, PID: 29051
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.user.testapp/com.example.user.testapp.RevGPAActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.example.user.testapp.RevGPAActivity.onCreate(RevGPAActivity.java:10)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Solved my own problem. If someone stumbled on the same error, the target activity should be extending Activity not ActionBarActivity
You need to use a Theme.AppCompat theme (or descendant) with this activity
As you see in log file: You need to use a Theme.AppCompat theme (or descendant) with this activity could you check `#style/AppTheme" in style.xml of your project, this style need have parent="#style/Theme.AppCompat" or descendant ò