This is my simple Camera Intent Demo in which i have only one Activity .....
package x.y;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;
public class PhotoShoot extends Activity {
final static int CAMERA_RESULT = 0;
ImageView imv;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAMERA_RESULT);
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == RESULT_OK)
{
Bundle extras = intent.getExtras();
Bitmap bmp = (Bitmap) extras.get("data");
imv = (ImageView) findViewById(R.id.ReturnedImageView);
imv.setImageBitmap(bmp);
}
}
}
And Layout main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/ReturnedImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>
Manifest ...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="x.y"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".PhotoShoot"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Throwing "Force close" after few seconds in Android emulator 2.2 from starting of Camera intent with following Exception ...
07-06 15:26:00.999: ERROR/AndroidRuntime(544): FATAL EXCEPTION: GLThread 11
07-06 15:26:00.999: ERROR/AndroidRuntime(544): java.lang.IllegalArgumentException: No configs match configSpec
07-06 15:26:00.999: ERROR/AndroidRuntime(544): at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:760)
07-06 15:26:00.999: ERROR/AndroidRuntime(544): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:916)
07-06 15:26:00.999: ERROR/AndroidRuntime(544): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1246)
07-06 15:26:00.999: ERROR/AndroidRuntime(544): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
any idea?
This is actually part of a bigger issue, and I'm hoping that by posting here, others who have experienced this error will read this entry. I equally hope that, if any of my conclusions are incorrect, someone comes forth with a more definitive explanation and/or solution.
The core issue is OpenGL support. Beginning at 2.2, Android supports OpenGL ES 2.0, and beginning at 4.0.3, Android emulators support OpenGL ES 2.0. Code that uses OpenGL ES 2.0 will not work on emulators before 4.0.3. [Evidently, the camera switched from ES 1.0 to 2.0 at Android 2.2]
But that's not all! None of the Android docs I've encountered mention that, in order to support Open GL ES 2.0 emulation, your box's graphic card chipset and driver must support OpenGL 2.0 as well. Therefore, if you enable GPU Emulation on the AVD and you still encounter this error, do the following:
1) Find out the specs on your graphic card and visit the chipset manufacturer's web site to determine if the chipset is OpenGL 2.0 compatible. If it isn't, you're S.O.L. and must stick to debugging through an actual Android device instead of an emulator.
2) Determine if you have the latest graphics driver for the chipset. Drivers obtained through Microsoft (if you're using Windows) typically do not support OpenGL, so you want to download the latest driver from the manufacturer.
I hope this helps.
Camera is not support in Android emulator so don't worry about it. This type of Error come in Android Emulator 2.2 and i have also Checked Android emulator 1.6 but not getting Error.
I have also checked above code in Android Device Samsung Galaxy Ace is working fine.
Related
My Mobile version is 12. Work App properly but I upgrade my software version of mobile then crushes.
Show this Error on my log:
2022-03-01 12:04:55.025 31242-31291/com.Solver.Solver E/AndroidRuntime: FATAL EXCEPTION: WorkManager-WorkManagerTaskExecutor-thread-0
Process: com.Solver.Solver, PID: 31242
java.lang.IllegalArgumentException: com.Solver.Solver: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:147)
at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:124)
at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:79)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
I am solved this error.
I Implements this code.
implementation "androidx.work:work-runtime:2.7.1"
Your passing unexpected flags into a PendingIntent.
For example:
int intentFlags = PendingIntent.FLAG_ONE_SHOT;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
intentFlags = PendingIntent.FLAG_ONE_SHOT|PendingIntent.FLAG_IMMUTABLE;
}
After several attempt to fix this, i gave up and try to contact Qiscus. And they release new version that handle this Pending Intent behaviour change. So if anyone use Qiscus and got this error, you can use latest tag
https://github.com/qiscus/qiscus-sdk-android/releases/tag/1.3.35
PendingIntent pendingIntent;
Intent openIntent = new Intent(context, QiscusPushNotificationClickReceiver.class);
openIntent.putExtra("data", comment);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getBroadcast(context, QiscusNumberUtil.convertToInt(comment.getRoomId()),
openIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT);
} else {
pendingIntent = PendingIntent.getBroadcast(context, QiscusNumberUtil.convertToInt(comment.getRoomId()),
openIntent, PendingIntent.FLAG_CANCEL_CURRENT);
}
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Trying to read a file from the downloads directory for an application I'm working on, and I cannot for the life of me get it to open the dialog for the user to give permission to access files.
Trying to add the ability to import data from a file the user can download from another site. Attempting to open the file from the download folder is nothing but failure. Finally determine that it's definitely the permissions to access the file that aren't being enabled, and I can't get the dialog to allow permissions to ever come up. Give up and create a new app from scratch
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
paste in the android developer site example of how to enable permissions and that gives errors from scratch in the android development studio.
"Wrong 1st argument type. Found: 'android.content.Context', required: 'android.app.Activity'
Inspection info:
shouldShowRequestPermissionRationale (android.app.Activity,String)
in ActivityCompat cannot be applied to (android.content.Context,String)"
using (activity)this works to remove the error, but doesn't give much trust in the android docs at this point.
Still can't get the permission dialog to come up. Try several other examples and Stackoverflow "solutions" with no joy.
finish basic app from scratch, stick in some printlns to show progress, no dialog in the emulator or on my phone. Logcat shows that the everything seems to be working in the process, it's finding the permission no allowed, branching to the part to ask for it, then testing to see if the response allowed it, except for the part where it actually opens a dialog. I've had no luck finding anything relevant on the egl errors.
Example logcat:
07-20 08:30:19.999 23735-23735/anticlimacticteleservices.myapplication I/System.out: need to ask for permission
07-20 08:30:20.014 23735-23775/anticlimacticteleservices.myapplication D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
07-20 08:30:20.049 23735-23775/anticlimacticteleservices.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
07-20 08:30:20.050 23735-23775/anticlimacticteleservices.myapplication W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
07-20 08:30:20.096 23735-23775/anticlimacticteleservices.myapplication D/EGL_emulation: eglCreateContext: 0xaaa757e0: maj 2 min 0 rcv 2
07-20 08:30:20.099 23735-23775/anticlimacticteleservices.myapplication D/EGL_emulation: eglMakeCurrent: 0xaaa757e0: ver 2 0 (tinfo 0xac396210)
07-20 08:30:20.133 23735-23775/anticlimacticteleservices.myapplication D/EGL_emulation: eglMakeCurrent: 0xaaa757e0: ver 2 0 (tinfo 0xac396210)
07-20 08:30:20.181 23735-23735/anticlimacticteleservices.myapplication I/System.out: You denied write external storage permission.
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private static final int PERMISSION_REQUEST_CODE = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Context thisActivity = this;
try{
int writeExternalStoragePermission = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if(writeExternalStoragePermission!= PackageManager.PERMISSION_GRANTED){
System.out.println("need to ask for permission");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
}else {
System.out.println("it actually has permission now");
}
}catch (Exception ex) {
System.out.println("failed to get permissions with "+ex.getMessage());
}
}
#Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode == PERMISSION_REQUEST_CODE) {
int grantResultsLength = grantResults.length;
if(grantResultsLength > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED) {
System.out.println("You did it finally");
}else {
System.out.println("You denied write external storage permission.");
}
}
}
}
I expect a dialog to pop up allowing me to grant the neccesary permission to open a file in the download folder.
Your manifest has:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Your Java code does not refer to READ_EXTERNAL_STORAGE. It refers to WRITE_EXTERNAL_STORAGE. Those need to match.
To fix this:
Decide whether you need to write or not
If the answer to #1 is "yes, I need to write", switch your manifest to refer to WRITE_EXTERNAL_STORAGE
If the answer to #1 is "no, reading is fundamental", switch your Java code to refer to READ_EXTERNAL_STORAGE
FWIW, this sample app from this book demonstrates the use of WRITE_EXTERNAL_STORAGE.
I have a provider in my app
<provider android:authorities="com.myapp.android.provider" android:exported="false" android:name="com.myapp.android.provider.FileSystemProvider">
<grant-uri-permission android:pathPrefix="/"/>
</provider>
And when I call the following intent:
Intent intent = new Intent();
intent.setClassName(getPackageName(), "com.myapp.android.CameraActivity");
intent.setData(Uri.parse("content://com.myapp.android.provider/"));
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
| Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
I get exception
Caused by: java.lang.SecurityException: Permission Denial: starting
Intent { dat=content://com.myapp.android.provider/ flg=0xc3
cmp=com......../com......... (has extras) } from
ProcessRecord{44955bc0 9477:com...../u0a260} (pid=9477,
uid=10260) not exported from uid 10261
What I do wrong? I tried to specify full path to a file or different directory, but it never worked.
intent.setClassName(getPackageName(), "com.myapp.android.CameraActivity");
Most likely, this is not the actual line of code that is in your app; your real code is specifying some other app. Regardless, this component is not exported, and therefore you cannot access it from your app.
<provider android:authorities="com.myapp.android.provider"
android:exported="true"<----- change android:name="com.myapp.android.provider.FileSystemProvider">
<grant-uri-permission android:pathPrefix="/"/>
</provider>
There is an existing question similar to this one here: Motion Recognition Manager and motion-Service in android
I'm asking mine because there is a comment requesting the code where the error happens and the code was not provided. It's my first question here, so I hope I'm not doing something wrong or rude.
I'm working on an app which parses RSS feeds and has settings the user can change, like background color, text color, username. These settings are saved in shared preferences.
The app works perfectly in an emulator. In previous iterations, before I added the shared preference functionality, I was able to run the app on my personal Samsung Galaxy s6 phone. Now, it won't run on my phone.
I am displaying the feeds in a ListView. Settings are changed from ListPreferences.
My logcat looks like this:
10/30 10:33:34: Launching app
$ adb push C:\Users\Jennifer\AndroidStudioProjects\RSSAssignment7\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.example.jennifer.rssassignment7
$ adb shell pm install -r "/data/local/tmp/com.example.jennifer.rssassignment7"
pkg: /data/local/tmp/com.example.jennifer.rssassignment7
Success
$ adb shell am start -n "com.example.jennifer.rssassignment7/com.example.jennifer.rssassignment7.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 14137 on device samsung-sm_g920w8-1215fc28c4943e05
W/System: ClassLoader referenced unknown path: /data/app/com.example.jennifer.rssassignment7-1/lib/arm64
D/InjectionManager: InjectionManager
D/InjectionManager: fillFeatureStoreMap com.example.jennifer.rssassignment7
I/InjectionManager: Constructor com.example.jennifer.rssassignment7, Feature store :{}
I/InjectionManager: featureStore :{}
W/ResourcesManager: getTopLevelResources: /data/app/com.example.jennifer.rssassignment7-1/base.apk / 1.0 running in com.example.jennifer.rssassignment7 rsrc of package com.example.jennifer.rssassignment7
W/ResourcesManager: getTopLevelResources: /data/app/com.example.jennifer.rssassignment7-1/base.apk / 1.0 running in com.example.jennifer.rssassignment7 rsrc of package com.example.jennifer.rssassignment7
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
D/AbsListView: Get MotionRecognitionManager
E/MotionRecognitionManager: mSContextService = android.hardware.scontext.ISContextService$Stub$Proxy#8089b26
E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy#53d367
E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy#53d367
Application terminated.
And a code sample, one of the ListPreferences:
In preferences.xml:
<ListPreference
android:title="Choose Your Text Color"
android:summary="We'll save your choice for next time."
android:key="color"
android:defaultValue="#000000"
android:entries="#array/colorArray"
android:entryValues="#array/colorValues" />
In array.xml:
<!--color array-->
<string-array name="colorArray">
<item>Black - black text is not visible on a black background</item>
<item>Burgundy</item>
<item>Green</item>
<item>Blue</item>
<item>White - white text is not visible on a white background</item>
</string-array>
<string-array name="colorValues">
<item>#000000</item>
<item>#800020</item>
<item>#3C8D0D</item>
<item>#7068FF</item>
<item>#ffffff</item>
</string-array>
In the activity:
public class MainActivity extends AppCompatActivity { ...
TextView titleView, descriptionView;
titleView = (TextView) findViewById(R.id.titleView);
descriptionView = (TextView) findViewById(R.id.descriptionView);
//get text color and background color from shared preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
color = prefs.getString("color", "1");
if(!(color == null)) {
titleView.setTextColor(Color.parseColor(color));
descriptionView.setTextColor(Color.parseColor(color));
} else {
titleView.setTextColor(BLACK);
descriptionView.setTextColor(BLACK);
}
And the xml for the TextViews:
<TextView
android:layout_width="wrap_content"
android:id= "#+id/titleView"
android:layout_height="wrap_content"
style="#style/CodeFont"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id= "#+id/descriptionView"
style="#style/CodeFont"
android:layout_below="#+id/linkView"/>
I put in the else intending it as a default setting for the first time the app is run, with nothing saved in shared preferences. I'm not certain it's necessary, but I added it when the app was crashing on my phone, thinking that the reason it was crashing was that there were no stored settings.
The app installs on my phone and crashes immediately. I've tried to look at its settings, but there is never anything to change. I've tried uninstalling and reinstalling the app. Again, it won't work on my phone, but it works perfectly on an emulator.
Can anyone offer a suggestion to help get my app running on my phone? Thanks very much.
Seems "1" in color = prefs.getString("color", "1"); not a valid color value (Supported formats are: #RRGGBB #AARRGGBB or one of the following names: 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia', 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'.) Take look at Official Documentation
i am developing an android application using a new device (Samsung galaxy core) the problem is when I try to run the application and I have an error in my code like infinity loop or something like that when the application run in my device a black screen appears and i can't do nothing only restart the device and start over again I don't see the dialog ( force to close application ... ) which I used to have in my old device any help please !
thanks for you answers and sorry if i wasn't so clear actually the problem is not in my code it's in the device (i think) for example in this code i haven't declare a new activity in Androidmanifest.xml
package com.exadle.df;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.button);
final Intent intent = new Intent(MainActivity.this, newj.class);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
MainActivity.this.startActivity(intent);
}
});
}
}
so when the app crash a black screen appears and i can't do nothing ! even as you said "Hold the Home Button for couple of seconds, when the list of running applications shows up, flip your app out." the only thing i can do is Hold power Button to restart the phone
here is the logcat if it can help
05-25 15:04:32.281 21017-21017/com.exadle.df D/dalvikvm﹕ Late-enabling CheckJNI
05-25 15:04:32.401 21017-21017/com.exadle.df D/ActivityThread﹕ setTargetHeapUtilization:0.25
05-25 15:04:32.401 21017-21017/com.exadle.df D/ActivityThread﹕ setTargetHeapIdealFree:8388608
05-25 15:04:32.401 21017-21017/com.exadle.df D/ActivityThread﹕ setTargetHeapConcurrentStart:2097152
05-25 15:04:32.871 21017-21017/com.exadle.df D/libEGL﹕ loaded /system/lib/egl/libEGL_adreno200.so
05-25 15:04:32.881 21017-21017/com.exadle.df D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_adreno200.so
05-25 15:04:32.891 21017-21017/com.exadle.df D/libEGL﹕ loaded /system/lib/egl/libGLESv2_adreno200.so
05-25 15:04:32.891 21017-21017/com.exadle.df I/Adreno200-EGL﹕ <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.02.21.107_msm8625_JB_REL_2.0.3_CL3357771_release_AU (CL3357771)
Build Date: 02/25/13 Mon
Local Branch:
Remote Branch: quic/jb_rel_2.0.3
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_JB_REL_2.0.3.04.01.02.21.107 + NOTHING
05-25 15:04:32.941 21017-21017/com.exadle.df D/OpenGLRenderer﹕ Enabling debug mode 0
05-25 15:04:37.531 21017-21017/com.exadle.df D/AndroidRuntime﹕ Shutting down VM
05-25 15:04:37.531 21017-21017/com.exadle.df W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41b78438)
05-25 15:04:37.541 21017-21017/com.exadle.df E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.exadle.df/com.exadle.df.newj}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
at android.app.Activity.startActivityForResult(Activity.java:3429)
at android.app.Activity.startActivityForResult(Activity.java:3390)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
at android.app.Activity.startActivity(Activity.java:3600)
at android.app.Activity.startActivity(Activity.java:3568)
at com.exadle.df.MainActivity$1.onClick(MainActivity.java:25)
at android.view.View.performClick(View.java:4191)
at android.view.View$PerformClick.run(View.java:17229)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
i am using Android Studio and i can't use stop execution !
Without the code for your app, I can't tell why it is hanging.
If you think it is stuck in an infinite loop, you can use tools to determine roughly where the loop is. A good pace to start is with the profiling tools in the Android Development Kit, which will tell you the method where the loop is occurring.
If you show us some of the code or logcat, we may be able to help more. But, I can offer my bit of advice.
When I come across something in my apps that is not working right, or it crashes when it comes to that bit of code, I comment out a few blocks of code at a time, and find the point at which the app runs correctly. So If I had an app that crashed when a specific method was called, I would systematically comment out parts of that method until it stopped crashing. If it only stopped when the entire method was commented out, then I would need to go into the code and try to spot the problem. However, if you comment out half of the method and the remaining code runs, then you know that the problem is in something you commented out. Then you can narrow that down to the exact problem.
Just make sure you comment out blocks of code that make sense. Don't just comment out a bracket, and then have your program give you errors. Comment out the code intelligently.
Since your entire app isn't working, make sure that your preliminary activity is set correctly in your Manifest. If it is your splash, make sure that it is called when the app starts. There is a setting/line of code in the manifest somewhere, but I forget where it is. If all of that is correct, then start commenting out the code in that activity systematically. Start with the last method called, then the second to last, and so on. When it starts running, look at the code you have commented out and try to find the problem.
This is all we can do without any code or logcat. If the problem turns out not to be in the code, but in the phone, then this would be better suited on the Android Enthusiasts forum. You could ask for a migration if this is the case. Hope this helps!
UPDATE
I am still not 100% sure what the problem is, but I can suggest some changes in your code that may or may not work.
Make sure your newj activity is in your Manifest.XML. There should be a line of code that says:
<activity android:theme="#style/AppBaseTheme" android:screenOrientation="portrait" android:name="newj"></activity>
If that doesn't help at all, you can try these also.
Instead of having your intent outside the click listener, put in inside. I find that having not in the same OnClickListener or if statement or method can cause a problem to two. So your code would be:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Intent intent = new Intent(MainActivity.this, newj.class);
startActivity(intent); //and get rid of MainActivity.this.
}
});
If that doesn't work, then this method is more in-depth, but I think it is safer.
First, you want to go into the XML for your button, and add these two lines.
android:Clickable="true"
android:onClick="methodToBeCalled"
These two lines take the place of the OnClickListener, and make the button clickable and tell the program which method to call when the button is clicked. So you need to make a new method, outside of onCreate, that looks like this.
public static void methodToBeCalled(View view){
final Intent intent = new Intent(MainActivity.this, newj.class);
startActivity(intent);
}
So basically what happens is that the code in the XML makes the button clickable, and says to call the method, "methodToBeCalled" when it is clicked. Then it looks for that method in your mainActivity class (because that XML file is linked to this activity) and it runs that activity, starting the Intent intent which starts the Activity newj. Confusing, right? Not really. The XML tells the program to run the method "methodToBeCalled", which starts newj.
Try these methods in order. If method 1 doesn't work, move onto 2. Then 3. If none of these work, update your question with the new logcat, your entire MainActivity code, your entire activity_main XML code, and your entire AndroidManifest.XML code. We can move on from there.
If this does turn out to be a problem with your phone and not the code, flag for migration to Android Enthusiasts Stack Exchange. You will get better help there if this does turn out to be a problem with the phone itself, and not the code.
Hope this helps!