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.
Related
Issue:
I am getting the following error:
java.lang.IllegalArgumentException: No available camera can be found.
when calling and instance method ProcessCameraProvider.bindToLifecycle(). See this in the context of the code below by searching for "------ Code Crashes Here --------------".
Question:
How do I prevent this error and subsequent crashing of the app? More specifically, how do I ensure the CameraSelector can return a camera instance for the Nexus 6?
Hypothesis
It appears there is something wrong with the CameraSelector used in this call. If I set a breakpoint on the bindToLifecycle line, and debug up to that point and add a watch for `cameraProvider.hasCamera(cameraSelector) it returns false. Maybe this is not intended to return true until the bindToLifecycle method has been called. If so, how can I verify the cameraSelector object has been created sucessfully (successfully meaning it points to an actual camera object)?
In the creation of the cameraSelector object, I use the requireLensFacing method in the builder, so it appears the Nexus 6 hardware does not tag anything with these LENS_FACING_BACK or LENS_FACING_FRONT and therefore does not return any camera instance? Do I understand this correctly?
I should note that this error did not occur when the exact same code was run on a Nexus 5, which is why I am inclined to think it is a hardware issue.
I also tried the LENS_FACING_FRONT int, but had the same error. If I remove the requireLensFacing build component altogether I get a different error:
java.util.NoSuchElementException
Code
package jp.oist.cameraxapp;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.Camera;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.ImageAnalysis;
import androidx.camera.core.ImageCapture;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.Preview;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.camera.view.PreviewView;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class MainActivity extends AppCompatActivity {
private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;
private ExecutorService executor;
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
executor = Executors.newSingleThreadExecutor();
PreviewView previewView = findViewById(R.id.previewView);
cameraProviderFuture = ProcessCameraProvider.getInstance(this);
cameraProviderFuture.addListener(() -> {
try {
// Camera provider is now guaranteed to be available
ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
// Set up the view finder use case to display camera preview
Preview preview = new Preview.Builder().build();
// Choose the camera by requiring a lens facing
CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
.build();
// Connect the preview use case to the previewView
preview.setSurfaceProvider(
previewView.createSurfaceProvider());
// Set up the capture use case to allow users to take photos
ImageCapture imageCapture = new ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.build();
ImageAnalysis imageAnalysis =
new ImageAnalysis.Builder()
.build();
imageAnalysis.setAnalyzer(executor, new ImageAnalysis.Analyzer() {
#Override
public void analyze(#NonNull ImageProxy image) {
int rotationDegrees = image.getImageInfo().getRotationDegrees();
Log.i("CameraXApp3", "Image Analyzed");
image.close();
}
});
// Attach use cases to the camera with the same lifecycle owner
// ------ Code Crashes Here --------------
Camera camera = cameraProvider.bindToLifecycle(
((LifecycleOwner) this),
cameraSelector,
preview,
imageCapture);
} catch (InterruptedException | ExecutionException e) {
// Currently no exceptions thrown. cameraProviderFuture.get() should
// not block since the listener is being called, so no need to
// handle InterruptedException.
}
}, ContextCompat.getMainExecutor(this));
}
}
Full logcat surrounding the IllegalArgumentException
2020-07-29 13:31:57.954 7345-7345/? E/Finsky: [2] VerifyPerSourceInstallationConsentInstallTask.b(2): Package name null is not an installed package
2020-07-29 13:31:59.660 462-877/? E/cutils: Failed to open(/data/misc/profiles/cur/0/jp.oist.cameraxapp/primary.prof): No such file or directory
2020-07-29 13:31:59.660 462-877/? E/installed: Failed to prepare /data/misc/profiles/cur/0/jp.oist.cameraxapp/primary.prof: No such file or directory
2020-07-29 13:31:59.661 729-756/? E/ArtManagerService: Failed to prepare profile for jp.oist.cameraxapp:/data/app/jp.oist.cameraxapp-HSYslGAf7kOyD4tEcVKEkw==/base.apk
2020-07-29 13:32:00.305 462-877/? E/installd: Failed to delete /data/app/vmdl841803495.tmp: No such file or directory
2020-07-29 13:32:00.846 729-729/? E/LoadedApk: Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/sk.baka.aedict3-FT98hpKmmu7AEcH7jl4_Lw==/lib/arm, /data/app/sk.baka.aedict3-FT98hpKmmu7AEcH7jl4_Lw==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.LoadedApk.createAppFactory(LoadedApk.java:226)
at android.app.LoadedApk.updateApplicationInfo(LoadedApk.java:338)
at android.app.ActivityThread.handleDispatchPackageBroadcast(ActivityThread.java:5441)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1740)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at com.android.server.SystemServer.run(SystemServer.java:500)
at com.android.server.SystemServer.main(SystemServer.java:322)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:839)
2020-07-29 13:32:00.847 729-729/? E/LoadedApk: Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/sk.baka.aedict3-FT98hpKmmu7AEcH7jl4_Lw==/lib/arm, /data/app/sk.baka.aedict3-FT98hpKmmu7AEcH7jl4_Lw==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.LoadedApk.createAppFactory(LoadedApk.java:226)
at android.app.LoadedApk.updateApplicationInfo(LoadedApk.java:338)
at android.app.ActivityThread.handleDispatchPackageBroadcast(ActivityThread.java:5441)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1740)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at com.android.server.SystemServer.run(SystemServer.java:500)
at com.android.server.SystemServer.main(SystemServer.java:322)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:839)
2020-07-29 13:32:02.251 11105-11105/jp.oist.cameraxapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: jp.oist.cameraxapp, PID: 11105
java.lang.IllegalArgumentException: No available camera can be found.
at androidx.camera.core.CameraSelector.filter(CameraSelector.java:100)
at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:389)
at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:275)
at jp.oist.cameraxapp.MainActivity.lambda$onCreate$0$MainActivity(MainActivity.java:80)
at jp.oist.cameraxapp.-$$Lambda$MainActivity$N0aObN0KVyRMowRsss_pmN8BZ44.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6698)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:859)
2020-07-29 13:32:02.367 2459-9800/ch.deletescape.lawnchair.ci E/pe.lawnchair.c: Failed to open APK '/data/app/jp.oist.cameraxapp-bhz9WJnVll-cJYJKM51yGg==/base.apk' I/O error
2020-07-29 13:32:02.368 2459-9800/ch.deletescape.lawnchair.ci E/ResourcesManager: failed to add asset path /data/app/jp.oist.cameraxapp-bhz9WJnVll-cJYJKM51yGg==/base.apk
Full logcat surrounding the NoSuchElementException
2020-07-29 13:31:22.712 10962-10962/jp.oist.cameraxapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: jp.oist.cameraxapp, PID: 10962
java.util.NoSuchElementException
at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:759)
at java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:780)
at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:415)
at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:275)
at jp.oist.cameraxapp.MainActivity.lambda$onCreate$0$MainActivity(MainActivity.java:79)
at jp.oist.cameraxapp.-$$Lambda$MainActivity$N0aObN0KVyRMowRsss_pmN8BZ44.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6698)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:859)
2020-07-29 13:31:22.758 382-382/? E/lowmemorykiller: Error writing /proc/10962/oom_score_adj; errno=22
Edit1:
Tested standard camera app on the Nexus 6 and found that it also crashed. This pointed to a HAL issue presented by a commenter. Restarted the Nexus 6 in an effort to fix the HAL. Now logcat presents a whole new set of errors, but I will save that for a seperate question if I cannot resolve them on my own.
With both LENS_FACING_FRONT and LENS_FACING_BACK resulting in a no available camera can be found, it seems as though no cameras on the device are available for use, this may be caused at times by a HAL crash, and might require a device reboot for the HAL to function correctly again.
You should check the native camera app (or any other camera app for that matter) to see if they are working on the nexus 6 device. If they aren't, then you'll know the issue is in the camera HAL.
I have an android app that does not require a log in, but I do have Anonymous sign-in enabled so that I can retrieve the userID from Firebase and use it to log specific events. I have the feeling that it just stopped retrieving the UID from Firebase.
What I've done to resolve the issue is the following:
updated all the dependencies
updated the emulator
Installed a new emulator
re-added the google services plugin
re-added google-services.json file
updated Android Manifest
I've tried to create a login-activity for the sake of testing, where through a button with an onclicklisterer, the user get's anoynmously logged in.
I've doubled checked Local History in Android Studio to see whether big changes were made to the code, not the case. See screenshot
Enabled and disabled anonymous login from the Firebase Console.
Re-written the entire code based on documentation from Firebase.
I've basically tried every solution there is
My Manifest
<?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.superawesome.metime">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/wazzup"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Cardview" />
<activity android:name=".cardviewactivity" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxx" />
<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="com.google.firebase.auth.internal.FederatedSignInActivity"
tools:replace="android:launchMode"
android:launchMode="standard" />
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>
My code:
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true; // go back to the first screen
case R.id.cardoverview:
startActivity(new Intent(this, cardviewactivity.class));
return true; //go to the screen where all the swiped right activities are stored
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
#Override
public void onComplete(#NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w("This Tag", "getInstanceId failed", task.getException());
return;
} else {
Log.d("This tag", "We need this");
}
}
});
swipeDb = FirebaseDatabase.getInstance().getReference().child("Users");
final FirebaseFirestore db = FirebaseFirestore.getInstance();
//Anonymous user login to be registered in Firebase
mAuth = FirebaseAuth.getInstance();
mCurrentUser = mAuth.getCurrentUser(); // save the UID of the user in users in Firebase without having to log in
final String UID = mCurrentUser.getUid();
DatabaseReference currentUserDb = FirebaseDatabase.getInstance().getReference().child("Users").child("UID");
currentUserDb.setValue(UID); //save the User UID to the Firebase Realtime database
// Calling to the AdMob API to add advertisements to the banner in the main view.Gotta make that dough
// Change this to big cards in the future
final AdView adView = findViewById(R.id.adView);
final AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
Screenshot to Firebase Authentication
Error I'm receiving from the logcat:
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
I/FirebaseCrashlytics: Initializing Crashlytics 17.0.0
I/FirebaseInitProvider: FirebaseApp initialization successful
I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
V/FA: onActivityCreated
W/rawesome.metim: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
V/FA: App measurement disabled via the init parameters
I/FA: App measurement initialized, version: 28000
To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.superawesome.metime
D/FA: Debug-level message logging enabled
V/FA: Detected application was in foreground
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.superawesome.metime, PID: 21746
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.superawesome.metime/com.superawesome.metime.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3341)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2045)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7478)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
at com.superawesome.metime.MainActivity.onCreate(MainActivity.java:118)
at android.app.Activity.performCreate(Activity.java:7989)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3316)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3485)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2045)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7478)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
V/FA: Connecting to remote service
D/FA: Event not sent since app measurement is disabled
com.superawesome.metime.MainActivity.onCreate(MainActivity.java:118) --> final String UID = mCurrentUser.getUid();
I've been trying to resolve this issue for over a week now with no success
Edit:
I know I can add listeners to see if the user is anonymously signed in or not. The whole problem around this is that the user is not being signed in anymore at all.
Edit2:
From logcat:
2020-05-30 12:39:53.655 23257-23297/com.superawesome.metime I/DynamiteModule: Selected remote version of com.google.android.gms.ads.dynamite, version >= 21600
2020-05-30 12:39:53.658 23257-23297/com.superawesome.metime V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
2020-05-30 12:39:53.770 23257-23311/com.superawesome.metime I/TetheringManager: registerTetheringEventCallback:com.superawesome.metime
2020-05-30 12:39:53.818 23257-23303/com.superawesome.metime W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
2020-05-30 12:39:54.025 23257-23303/com.superawesome.metime I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
2020-05-30 12:39:54.076 23257-23257/com.superawesome.metime I/FirebaseCrashlytics: Initializing Crashlytics 17.0.0
2020-05-30 12:39:54.220 23257-23257/com.superawesome.metime I/FirebaseInitProvider: FirebaseApp initialization successful
2020-05-30 12:39:54.332 23257-23332/com.superawesome.metime D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2020-05-30 12:39:54.342 23257-23332/com.superawesome.metime D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2020-05-30 12:39:54.362 23257-23332/com.superawesome.metime D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2020-05-30 12:39:54.527 23257-23315/com.superawesome.metime V/FA: App measurement disabled via the init parameters
2020-05-30 12:39:55.234 23257-23315/com.superawesome.metime I/FA: App measurement initialized, version: 28000
2020-05-30 12:39:55.247 23257-23315/com.superawesome.metime I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2020-05-30 12:39:55.267 23257-23315/com.superawesome.metime I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.superawesome.metime
2020-05-30 12:39:55.274 23257-23315/com.superawesome.metime D/FA: Debug-level message logging enabled
2020-05-30 12:39:57.009 23257-23315/com.superawesome.metime V/FA: Detected application was in foreground
2020-05-30 12:39:57.995 23257-23315/com.superawesome.metime V/FA: Connecting to remote service
2020-05-30 12:40:23.846 23257-23311/com.superawesome.metime W/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE. Will retry token retrieval
2020-05-30 12:41:23.931 23257-23311/com.superawesome.metime W/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE. Will retry token retrieval
2020-05-30 12:42:54.030 23257-23311/com.superawesome.metime W/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE. Will retry token retrieval
I have a mapsActivity that don't load correctly. The Api key is well
configured because if I call to maps activity after the splashScreen everything works OK. My emulator has installed api 26
This is the log when I call Mapsactivity after splashScreen.
> I/FA: App measurement initialized, version: 22048
> I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
> I/FA: To enable faster debug mode event logging run:
> adb shell setprop debug.firebase.analytics.app com.lyntia.android.mera
> D/FA: Debug-level message logging enabled
> D/SplashScreenActivity: User has logged in, token OK
> V/FA: onActivityCreated
> I/zygote: Background concurrent copying GC freed 15298(1332KB) AllocSpace objects, 11(220KB) LOS >objects, 55% free, 1238KB/2MB,
> paused 2.344ms total 101.117ms
> V/FA: Connecting to remote service
> V/FA: Connection attempt already in progress
> I/zzbz: Making Creator dynamically
> W/zygote: Skipping duplicate class check due to unrecognized classloader
> I/DynamiteModule: Considering local module com.google.android.gms.maps_dynamite:0 and remote module
> com.google.android.gms.maps_dynamite:221
> Selected remote version of com.google.android.gms.maps_dynamite, version >= 221
> V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
> V/FA: Connection attempt already in progress
> W/zygote: Skipping duplicate class check due to unrecognized classloader
> I/zygote: Do partial code cache collection, code=30KB, data=22KB
> After code cache collection, code=30KB, data=22KB
> I/zygote: Increasing code cache capacity to 128KB
> I/Google Maps Android API: Google Play services client version: 12451000
> I/Google Maps Android API: Google Play services package version: 16089022
> I/zygote: Do partial code cache collection, code=52KB, data=38KB
> I/zygote: After code cache collection, code=52KB, data=38KB
> Increasing code cache capacity to 256KB
> D/skia: --- SkAndroidCodec::NewFromStream returned null
> V/FA: Activity resumed, time: 3535145
> I/FA: Tag Manager is not found and thus will not be used
> D/OpenGLRenderer: HWUI GL Pipeline
> I/zygote: Do full code cache collection, code=83KB, data=87KB
> D/: HostConnection::get() New Host Connection established 0xa3a7c440, tid 15830
> I/OpenGLRenderer: Initialized EGL, version 1.4
> D/OpenGLRenderer: Swap behavior 1
> I/zygote: After code cache collection, code=81KB, data=65KB
> W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
> D/OpenGLRenderer: Swap behavior 0
> D/EGL_emulation: eglCreateContext: 0xa63060a0: maj 2 min 0 rcv 2
> V/FA: Connection attempt already in progress
> V/FA: Connection attempt already in progress
> D/EGL_emulation: eglMakeCurrent: 0xa63060a0: ver 2 0 (tinfo 0x88213db0)
> E/RecyclerView: No adapter attached; skipping layout
> D/: HostConnection::get() New Host Connection established 0x932f0040, tid 15826
> D/EGL_emulation: eglCreateContext: 0xa6305920: maj 1 min 0 rcv 1
> D/EGL_emulation: eglMakeCurrent: 0xa63060a0: ver 2 0 (tinfo 0x88213db0)
> D/EGL_emulation: eglMakeCurrent: 0xa6305920: ver 1 0 (tinfo 0x92ef6900)
> D/FA: Connected to remote service
> V/FA: Processing queued up service tasks: 5
> I/zygote: Do partial code cache collection, code=111KB, data=97KB
> I/zygote: After code cache collection, code=102KB, data=92KB
> I/zygote: Increasing code cache capacity to 512KB
> W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not >found.
> I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote >module
> com.google.android.gms.googlecertificates:4
> Selected remote version of com.google.android.gms.googlecertificates, version >= 4
> W/zygote: Skipping duplicate class check due to unrecognized classloader
> V/FA: Inactivity, disconnecting from the service
> I/zygote: Do full code cache collection, code=240KB, data=192KB
> After code cache collection, code=208KB, data=138KB
> I/zygote: Do partial code cache collection, code=245KB, data=187KB
> I/zygote: After code cache collection, code=245KB, data=187KB
> Increasing code cache capacity to 1024KB
This is the log when I call mapsActivity in they correct place (Don't work).
D/EGL_emulation: eglMakeCurrent: 0xa3de7c80: ver 2 0 (tinfo 0xa3918900)
D/EGL_emulation: eglMakeCurrent: 0xa3de7c80: ver 2 0 (tinfo 0xa3918900)
V/FA: Recording user engagement, ms: 1649
V/FA: Activity paused, time: 671631
V/FA: onActivityCreated
I/zygote: JIT allocated 56KB for compiled code of void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
I/zzbz: Making Creator dynamically
W/zygote: Skipping duplicate class check due to unrecognized classloader
I/DynamiteModule: Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:221
Selected remote version of com.google.android.gms.maps_dynamite, version >= 221
V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
W/zygote: Skipping duplicate class check due to unrecognized classloader
I/Google Maps Android API: Google Play services client version: 12451000
I/Google Maps Android API: Google Play services package version: 16089022
V/FA: Activity resumed, time: 672047
E/RecyclerView: No adapter attached; skipping layout
D/: HostConnection::get() New Host Connection established 0x9157a5c0, tid 7910
D/EGL_emulation: eglCreateContext: 0x911c7740: maj 1 min 0 rcv 1
D/EGL_emulation: eglMakeCurrent: 0xa3de7c80: ver 2 0 (tinfo 0xa3918900)
D/EGL_emulation: eglMakeCurrent: 0x911c7740: ver 1 0 (tinfo 0x90eec950)
D/EGL_emulation: eglMakeCurrent: 0xa3de7c80: ver 2 0 (tinfo 0xa3918900)
D/EGL_emulation: eglMakeCurrent: 0xa3de7c80: ver 2 0 (tinfo 0xa3918900)
W/DynamiteModule: Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
Selected remote version of com.google.android.gms.googlecertificates, version >= 4
W/zygote: Skipping duplicate class check due to unrecognized classloader
I/zygote: Do full code cache collection, code=471KB, data=305KB
After code cache collection, code=467KB, data=235KB
V/FA: Inactivity, disconnecting from the service
I/zygote: Do partial code cache collection, code=495KB, data=276KB
I/zygote: After code cache collection, code=495KB, data=276KB
Increasing code cache capacity to 2MB
activity_maps.xml
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3" />
MapsActivity.java
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
androidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MeraApp"
android:allowBackup="true"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Before mapsactivity there are some activities that get and post data from/to the server.
I don't know if it can be a problem with memory, cache...
Any help?
update
I am developing a small app which requires camera permission. I can handle the run time permission but the real problem is that when I relay to Sinchpayload and go to incomming call activity. This activity should request permissions (camera and other 2 permissions). But instead of showing the permission dialogue, it crash my app because of security exception. this thing happen only if I request camera permission - not happen to other permissions and only on Android 9 with camera "2" Api - Android 8.1 and lower works fine . THIS PROBLEM STILL HAPPEN WITH THE SINCH SAMPLE PUSH. The permission dialogue will show if start activity with intent as usual. This is the error :
-------- beginning of crash
2019-02-10 22:11:55.390 2113-2681/com.example.myapp.app E/AndroidRuntime: FATAL EXCEPTION: VideoCapturerThread
Process: com.example.myapp.app, PID: 2113
java.lang.SecurityException: validateClientPermissionsLocked:1054: Caller "com.example.myapp.app" (PID 10319, UID 2113) cannot open camera "1" without camera permission
at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:747)
at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:405)
at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:567)
at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:495)
at org.webrtc.Camera2Session.openCamera(Unknown Source:44)
at org.webrtc.Camera2Session.start(Unknown Source:60)
at org.webrtc.Camera2Session.<init>(Unknown Source:73)
at org.webrtc.Camera2Session.create(Unknown Source:17)
at org.webrtc.Camera2Capturer.createCameraSession(Unknown Source:17)
at org.webrtc.CameraCapturer$5.run(Unknown Source:52)
at android.os.Handler.handleCallback(Handler.java:891)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:207)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: android.os.ServiceSpecificException: validateClientPermissionsLocked:1054: Caller "com.example.myapp.app" (PID 10319, UID 2113) cannot open camera "1" without camera permission (code 1)
at android.os.Parcel.createException(Parcel.java:1967)
at android.os.Parcel.readException(Parcel.java:1921)
at android.os.Parcel.readException(Parcel.java:1871)
at android.hardware.ICameraService$Stub$Proxy.connectDevice(ICameraService.java:343)
at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:369)
at android.hardware.camera2.CameraManager.openCameraForUid(CameraManager.java:567)
at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:495)
at org.webrtc.Camera2Session.openCamera(Unknown Source:44)
at org.webrtc.Camera2Session.start(Unknown Source:60)
at org.webrtc.Camera2Session.<init>(Unknown Source:73)
at org.webrtc.Camera2Session.create(Unknown Source:17)
at org.webrtc.Camera2Capturer.createCameraSession(Unknown Source:17)
at org.webrtc.CameraCapturer$5.run(Unknown Source:52)
at android.os.Handler.handleCallback(Handler.java:891)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:207)
at android.os.HandlerThread.run(HandlerThread.java:65)`
and this is my code to request permissions :
if (Build.VERSION.SDK_INT>=23)
{
if (GlobalConstants.isAllPermissionsGrantedBefore_Video_Call(this)==false)
ActivityCompat.requestPermissions(
Video_incomming_call.this,
GlobalConstants.mPermissions_Video_Chat,
GlobalConstants.VIDEO_RECIEVE_CODE);
else {
Start_Calling();
}
} else Start_Calling();
The app permission dialog only shows in foreground.
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!