TextToSpeech android API 22 not playing audio - java

I am using text to speech engine in my App. It works fine on emulator Nexus 6 with API 23 and higher. But on emulator Nexus 6 with API 22 it does not speak.
Both emulators use Pico TTS as preferred engine.
My activity layout contains only one button "Speak".
This is my activity code:
public class MainActivity extends AppCompatActivity {
private TextToSpeech mTTS;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button speakBtn = findViewById(R.id.button);
speakBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
speak();
}
});
mTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = mTTS.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "Language not supported");
}
mTTS.setOnUtteranceProgressListener(new UtteranceProgressListener() {
#Override
public void onStart(String utteranceId) {
Log.d("TTS", "onStart called, utteranceId = " + utteranceId);
}
#Override
public void onDone(String utteranceId) {
Log.d("TTS", "onDone called, utteranceId = " + utteranceId);
}
#Override
public void onError(String utteranceId) {
Log.d("TTS", "onError called, utteranceId = " + utteranceId);
}
});
} else {
Log.e("TTS", "Initialization failed");
}
}
});
}
private void speak() {
Log.d("TTS", "speak() method called");
HashMap<String, String> map = new HashMap<>();
map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "greeting");
mTTS.speak("hello", TextToSpeech.QUEUE_FLUSH, map);
}
}
This is all logs from emulator Nexus 6 API 22:
02-18 13:54:09.942 9739-9739/? E/libprocessgroup: failed to make and chown /acct/uid_10059: Read-only file system
02-18 13:54:09.943 9739-9739/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
02-18 13:54:09.943 9739-9739/? I/art: Not late-enabling -Xcheck:jni (already on)
02-18 13:54:09.961 9739-9748/? E/art: Failed sending reply to debugger: Broken pipe
02-18 13:54:09.961 9739-9748/? I/art: Debugger is no longer active
02-18 13:54:09.992 9739-9739/? 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
02-18 13:54:10.001 9739-9739/? I/art: Rejecting re-init on previously-failed class java.lang.Class
02-18 13:54:10.001 9739-9739/? I/art: Rejecting re-init on previously-failed class java.lang.Class
02-18 13:54:10.064 9739-9739/? I/TextToSpeech: Sucessfully bound to com.svox.pico
02-18 13:54:10.072 9739-9757/? D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-18 13:54:10.074 9739-9739/? D/Atlas: Validating map...
02-18 13:54:10.093 9739-9739/? I/TextToSpeech: Connected to ComponentInfo{com.svox.pico/com.svox.pico.PicoService}
02-18 13:54:10.096 9739-9758/? I/TextToSpeech: Set up connection to ComponentInfo{com.svox.pico/com.svox.pico.PicoService}
02-18 13:54:10.111 9739-9757/? I/OpenGLRenderer: Initialized EGL, version 1.4
02-18 13:54:10.111 9739-9757/? W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
02-18 13:54:10.128 9739-9757/? D/EGL_emulation: eglCreateContext: 0xae434e20: maj 2 min 0 rcv 2
02-18 13:54:10.131 9739-9757/? D/EGL_emulation: eglMakeCurrent: 0xae434e20: ver 2 0
02-18 13:54:10.134 9739-9757/? D/OpenGLRenderer: Enabling debug mode 0
02-18 13:54:10.174 9739-9757/? D/EGL_emulation: eglMakeCurrent: 0xae434e20: ver 2 0
02-19 09:32:25.570 9739-9739/com.example.ttsapp D/TTS: speak() method called

Figured out how to solve the problem. Everything works if launch the emulator not via Debugging or Execution but from AVD Manager after starting Android Studio.

Related

My app shuts down when I don't give any input though I have mentioned the code for it

The app created finds whether the number is triangular or not. For more details, refer https://en.wikipedia.org/wiki/Triangular_number
Now, when I click on the button without giving any input in the TextView, the app shuts down abruptly. It shouldn't so because I already have an if statement for an empty string in the code.
package com.example.numbershapes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
class Number {
int number;
public boolean isTriangular() {
int x = 1;
int triangularNmbr = 1;
while (triangularNmbr < number) {
x++;
triangularNmbr += x;
}
if(triangularNmbr == number) {
return true;
}
else {
return false;
}
}
}
public class MainActivity extends AppCompatActivity {
public void testNumber(View view)
{
EditText usersNumber =
(EditText)findViewById(R.id.usersNumber);
String message = "";
if(usersNumber.getText().toString().isEmpty()){
message = "Please enter a number";
}
Number myNumber = new Number();
myNumber.number =
Integer.parseInt(usersNumber.getText().toString());
//will display on logcat
System.out.println(myNumber.isTriangular());
if(myNumber.isTriangular()){
message = myNumber.number + " is triangular" ;
}
else{
message = myNumber.number + " is not triangular" ;
}
Toast.makeText(getApplicationContext(), message,
Toast.LENGTH_LONG).show();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Also, I'm getting an error in Event Log. "Can't bind to local 8600 for debugger".
Can anybody explain what is it?
This is how the app looks
**
Logcat details when the app shuts down
**
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6662)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1118)
2019-09-08 00:38:56.005 4718-4718/? I/art: at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2599)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:2707)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.ActivityThread.-wrap12(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent, java.lang.String) (ActivityThread.java:-1)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1460)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.os.Looper.loop() (Looper.java:154)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6077)
2019-09-08 00:38:56.005 4718-4718/? I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:866)
2019-09-08 00:38:56.005 4718-4718/? I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:756)
2019-09-08 00:38:56.142 1314-1322/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2019-09-08 00:38:56.190 4718-4734/com.example.numbershapes I/OpenGLRenderer: Initialized EGL, version 1.4
2019-09-08 00:38:56.190 4718-4734/com.example.numbershapes D/OpenGLRenderer: Swap behavior 1
2019-09-08 00:38:56.192 4718-4734/com.example.numbershapes W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-09-08 00:38:56.192 4718-4734/com.example.numbershapes D/OpenGLRenderer: Swap behavior 0
2019-09-08 00:38:56.320 4718-4734/com.example.numbershapes D/EGL_emulation: eglCreateContext: 0x8d11ba20: maj 2 min 0 rcv 2
2019-09-08 00:38:56.596 4718-4734/com.example.numbershapes D/EGL_emulation: eglMakeCurrent: 0x8d11ba20: ver 2 0 (tinfo 0x9b763770)
2019-09-08 00:38:56.634 4718-4718/com.example.numbershapes W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
2019-09-08 00:38:56.693 4718-4734/com.example.numbershapes D/EGL_emulation: eglMakeCurrent: 0x8d11ba20: ver 2 0 (tinfo 0x9b763770)
2019-09-08 00:38:56.996 1601-1621/? I/ActivityManager: Displayed com.example.numbershapes/.MainActivity: +1s767ms
2019-09-08 00:38:57.010 1671-1862/? D/EGL_emulation: eglMakeCurrent: 0xa8e855a0: ver 2 0 (tinfo 0xa8e83640)
2019-09-08 00:38:57.035 1601-1751/? I/WindowManager: Destroying surface Surface(name=com.android.systemui/com.android.systemui.recents.RecentsActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2016 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:882 com.android.server.wm.WindowState.destroyOrSaveSurface:2100 com.android.server.wm.WindowManagerService.tryStartExitingAnimation:3024 com.android.server.wm.WindowManagerService.relayoutWindow:2904 com.android.server.wm.Session.relayout:224 android.view.IWindowSession$Stub.onTransact:286 com.android.server.wm.Session.onTransact:145
2019-09-08 00:38:57.192 1601-1621/? I/WindowManager: Destroying surface Surface(name=Starting com.example.numbershapes) called by com.android.server.wm.WindowStateAnimator.destroySurface:2016 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:882 com.android.server.wm.WindowState.destroyOrSaveSurface:2100 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.WindowStateAnimator.stepAnimationLocked:491 com.android.server.wm.WindowAnimator.updateWindowsLocked:303 com.android.server.wm.WindowAnimator.animateLocked:704
2019-09-08 00:38:58.432 1360-1394/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 5063852 , only wrote 4803840
2019-09-08 00:39:00.016 1671-1862/? D/EGL_emulation: eglMakeCurrent: 0xa8e855a0: ver 2 0 (tinfo 0xa8e83640)
2019-09-08 00:39:00.232 4718-4718/com.example.numbershapes D/AndroidRuntime: Shutting down VM
2019-09-08 00:39:00.241 4718-4718/com.example.numbershapes E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.numbershapes, PID: 4718
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:5610) 
at android.view.View$PerformClick.run(View.java:22265) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.Integer.parseInt(Integer.java:533)
at java.lang.Integer.parseInt(Integer.java:556)
at com.example.numbershapes.MainActivity.testNumber(MainActivity.java:36)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
at android.view.View.performClick(View.java:5610) 
at android.view.View$PerformClick.run(View.java:22265) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
2019-09-08 00:39:00.241 1360-1393/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 4803995 , only wrote 4803840
2019-09-08 00:39:00.244 1601-1612/? W/ActivityManager: Force finishing activity com.example.numbershapes/.MainActivity
2019-09-08 00:39:00.325 1601-4290/? I/OpenGLRenderer: Initialized EGL, version 1.4
2019-09-08 00:39:00.325 1601-4290/? D/OpenGLRenderer: Swap behavior 1
2019-09-08 00:39:00.327 1601-4290/? W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-09-08 00:39:00.327 1601-4290/? D/OpenGLRenderer: Swap behavior 0
2019-09-08 00:39:00.347 1601-4290/? D/EGL_emulation: eglCreateContext: 0x8ec4d1c0: maj 2 min 0 rcv 2
2019-09-08 00:39:00.368 1601-4290/? D/EGL_emulation: eglMakeCurrent: 0x8ec4d1c0: ver 2 0 (tinfo 0x8e191ff0)
2019-09-08 00:39:00.405 1601-4290/? D/EGL_emulation: eglMakeCurrent: 0x8ec4d1c0: ver 2 0 (tinfo 0x8e191ff0)
2019-09-08 00:39:00.758 1601-1614/? W/ActivityManager: Activity pause timeout for ActivityRecord{aa667d7 u0 com.example.numbershapes/.MainActivity t26 f}
2019-09-08 00:39:00.803 1314-1322/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 2691072
2019-09-08 00:39:00.842 1314-1314/? E/EGL_emulation: tid 1314: eglCreateSyncKHR(1901): error 0x3004 (EGL_BAD_ATTRIBUTE)
2019-09-08 00:39:01.450 2026-2273/? D/EGL_emulation: eglMakeCurrent: 0xa8e85420: ver 2 0 (tinfo 0xa8e838e0)
2019-09-08 00:39:01.938 2026-2273/? W/OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
2019-09-08 00:39:01.952 1601-1614/? I/ActivityManager: Killing 3960:com.google.android.apps.photos/u0a63 (adj 906): empty for 3445s
2019-09-08 00:39:02.006 1601-1658/? D/ActivityManager: cleanUpApplicationRecord -- 3960
2019-09-08 00:39:03.453 1360-1394/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 5110293 , only wrote 4957920
2019-09-08 00:39:14.093 1601-1614/? W/ActivityManager: Activity destroy timeout for ActivityRecord{aa667d7 u0 com.example.numbershapes/.MainActivity t26 f}
2019-09-08 00:39:14.098 1601-1614/? I/WindowManager: Destroying surface Surface(name=com.example.numbershapes/com.example.numbershapes.MainActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2016 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:882 com.android.server.wm.WindowState.removeLocked:1456 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2484 com.android.server.wm.WindowManagerService.removeWindowLocked:2442 com.android.server.wm.WindowManagerService.removeWindowLocked:2311 com.android.server.wm.AppWindowToken.removeAllWindows:530 com.android.server.wm.AppWindowToken.removeAppFromTaskLocked:326
2019-09-08 00:39:16.767 1314-1326/? W/SurfaceFlinger: Timed out waiting for hw vsync; faking it
2019-09-08 00:39:17.955 1601-1621/? I/Choreographer: Skipped 37 frames! The application may be doing too much work on its main thread.
When I run it it throws an exception. Your line number may differ but the reason is the same:
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.Integer.parseInt(Integer.java:620)
at java.lang.Integer.parseInt(Integer.java:643)
at stackoverflow57836483.MainActivity.testNumber(MainActivity.java:39)
problematic line is:
myNumber.number = Integer.parseInt(usersNumber.getText().toString());
But the real reason occurs earlier.
Here you already know the input is invalid but you continue execution and parsing it as a number.
if(usersNumber.getText().toString().isEmpty()){
message = "Please enter a number";
}
You should put everything that comes after into else { } except showing Toast. Correct code would be:
public void testNumber(View view)
{
EditText usersNumber = (EditText)findViewById(R.id.usersNumber);
String message = "";
if(usersNumber.getText().toString().isEmpty()){
message = "Please enter a number";
} else { // ELSE STARTS HERE...
Number myNumber = new Number();
myNumber.number = Integer.parseInt(usersNumber.getText().toString());
//will display on logcat
System.out.println(myNumber.isTriangular());
if(myNumber.isTriangular()){
message = myNumber.number + " is triangular" ;
}
else{
message = myNumber.number + " is not triangular" ;
}
} // AND ENDS HERE
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}

Android get json from webhost to add markers ERROR E/zygote64

i am making one project example to get json coordinates from 000webhost and show marks in maps in Android.
This is my java main code:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener,GoogleMap.OnMarkerClickListener {
private GoogleMap mMap;
public static final String URL="http://rrsaikat.mydiscussion.net/myjson/location.php";
private JSONArray result;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
return;
}
mMap.setMyLocationEnabled(true);
RequestQueue requestQueue= Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest=new StringRequest(Request.Method.GET, URL, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Log.d("JSONResult" , response.toString());
JSONObject j = null;
try{
j =new JSONObject(response);
result = j.getJSONArray("FL");
for(int i=0;i<result.length();i++){
JSONObject jsonObject1=result.getJSONObject(i);
String lat_i = jsonObject1.getString("1");
String long_i = jsonObject1.getString("2");
mMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(lat_i) , Double.parseDouble(long_i)))
.title(Double.valueOf(lat_i).toString() + "," + Double.valueOf(long_i).toString())
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(23.6850,90.3563), 6.0f));
}
}catch (NullPointerException e){
e.printStackTrace();
}
catch (JSONException e){
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
Toast.makeText(MapsActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
});
int socketTimeout = 10000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);
}
#Override
public void onLocationChanged(Location location) {
}
#Override
public void onStatusChanged(String s, int i, Bundle bundle) {
}
#Override
public void onProviderEnabled(String s) {
}
#Override
public void onProviderDisabled(String s) {
}
#Override
public boolean onMarkerClick(Marker marker) {
return false;
}
But i dont have the marks in Android and i have this debug:
W/zygote64: 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:220 I/DynamiteModule: Selected
remote version of com.google.android.gms.maps_dynamite, version >= 220
W/zygote64: 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: 12685023 I/zygote64: Do partial code cache
collection, code=23KB, data=29KB
After code cache collection, code=23KB, data=29KB
Increasing code cache capacity to 128KB E/zygote64: The String#value field is not present on Android versions >= 6.0
D/NetworkSecurityConfig: No Network Security Config specified, using
platform default I/System.out: (HTTPLog)-Static: isSBSettingEnabled
false I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/zygote64: Do partial code cache collection, code=61KB, data=59KB
D/TcpOptimizer: TcpOptimizer-ON I/zygote64: After code cache
collection, code=61KB, data=59KB
Increasing code cache capacity to 256KB D/ViewRootImpl#82b5652[MapsActivity]: setView =
DecorView#42ced23[MapsActivity] TM=true MM=false
D/ViewRootImpl#4f69478[Launcher]: MSG_WINDOW_FOCUS_CHANGED 0
D/ViewRootImpl#82b5652[MapsActivity]: dispatchAttachedToWindow
V/Surface: sf_framedrop debug : 0x4f4c, game : false, logging : 0
D/ViewRootImpl#82b5652[MapsActivity]: Relayout returned:
old=[0,0][0,0] new=[0,0][1080,2220] result=0x7 surface={valid=true
490213584896} changed=true D/mali_winsys: EGLint
new_window_surface(egl_winsys_display *, void *, EGLSurface,
EGLConfig, egl_winsys_surface **, egl_color_buffer_format *,
EGLBoolean) returns 0x3000, [1080x2220]-format:1 D/OpenGLRenderer:
eglCreateWindowSurface = 0x7230f51fa0
D/ViewRootImpl#82b5652[MapsActivity]: MSG_RESIZED_REPORT:
frame=Rect(0, 0 - 1080, 2220) ci=Rect(0, 63 - 0, 0) vi=Rect(0, 63 - 0,
0) or=1
MSG_WINDOW_FOCUS_CHANGED 1 V/InputMethodManager: Starting input:
tba=android.view.inputmethod.EditorInfo#9c8881 nm :
com.a9831.sapires.samuel9831 ic=null I/InputMethodManager:
startInputInner - mService.startInputOrWindowGainedFocus V/Surface:
sf_framedrop debug : 0x4f4c, game : false, logging : 0 V/Surface:
sf_framedrop debug : 0x4f4c, game : false, logging : 0 D/mali_winsys:
EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface,
EGLConfig, egl_winsys_surface **, egl_color_buffer_format *,
EGLBoolean) returns 0x3000, [1080x2157]-format:2 D/OpenGLRenderer:
eglDestroySurface = 0x7242c28a00 D/ViewRootImpl#4f69478[Launcher]:
Relayout returned: old=[0,0][1080,2220] new=[0,0][1080,2220]
result=0x5 surface={valid=false 0} changed=true I/System.out:
(HTTPLog)-Static: isSBSettingEnabled false I/System.out:
(HTTPLog)-Static: isSBSettingEnabled false
D/ViewRootImpl#4f69478[Launcher]: dispatchDetachedFromWindow
D/InputEventReceiver: channel 'f8f1abc
com.a9831.sapires.samuel9831/com.a9831.sapires.samuel9831.Launcher
(client)' ~ Disposing input event receiver.
channel 'f8f1abc com.a9831.sapires.samuel9831/com.a9831.sapires.samuel9831.Launcher
(client)' ~NativeInputEventReceiver. I/zygote64: Do full code cache
collection, code=124KB, data=118KB I/zygote64: After code cache
collection, code=111KB, data=63KB 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/zygote64:
Skipping duplicate class check due to unrecognized classloader
I/zygote64: Do partial code cache collection, code=122KB, data=79KB
I/zygote64: After code cache collection, code=122KB, data=79KB
Increasing code cache capacity to 512KB I/zygote64: Compiler allocated 4MB to compile void
com.google.maps.api.android.lib6.gmm6.vector.bs.b(javax.microedition.khronos.opengles.GL10)
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false I/System.out:
(HTTPLog)-Static: isSBSettingEnabled false V/InputMethodManager:
Starting input: tba=android.view.inputmethod.EditorInfo#b8feb38 nm :
com.a9831.sapires.samuel9831 ic=null I/InputMethodManager:
startInputInner - mService.startInputOrWindowGainedFocus
D/ViewRootImpl#82b5652[MapsActivity]: performDraw() was skipped by
AOD_SHOW_STATE... DisplayState=3 D/ViewRootImpl#82b5652[MapsActivity]:
MSG_WINDOW_FOCUS_CHANGED 0 D/OpenGLRenderer: eglDestroySurface =
0x7230f51fa0
The only RED error is:
E/zygote64: The String#value field is not present on Android versions >= 6.0
but the program dont stop and work but withou Markers.
Thks in advance

App crashes after button click when invalidating canvas view (Android Studio, Java)

My app crashes after clicking on the button when I call invalidate() to refresh the view. I can't figure out why. If I delete canvasView.invalidate(), the app does not crash. Is it allowed to call invalidate() from another class? I'm new to Android Studio. Surely, somebody can help me?
EDIT: the problem is solved, the answer is below, and I added the LogCat.
Here is the code:
public class MainActivity extends AppCompatActivity implements
View.OnClickListener {
CanvasView canvasView;
Button btnChangeColor;
static boolean colorRed;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CanvasView canvasView = new CanvasView(this, null);
btnChangeColor = (Button) findViewById(R.id.button);
btnChangeColor.setOnClickListener(this);
colorRed = false;
}
#Override
public void onClick(View v) {
if(colorRed) {
colorRed = false;
canvasView.invalidate();
return;
}
else {
colorRed = true;
canvasView.invalidate();
return;
}
}
}
class CanvasView extends View {
Paint paint;
public CanvasView(Context context, #Nullable AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(MainActivity.colorRed == true)
paint.setColor(Color.RED);
else
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(400, 400, 50, paint);
}
}
LogCat:
05-31 21:10:41.341 27902-27902/? I/art: Late-enabling -Xcheck:jni
Reinit property: dalvik.vm.checkjni= false
05-31 21:10:41.351 27902-27909/? I/art: Debugger is no longer active
Starting a blocking GC Instrumentation
05-31 21:10:41.425 27902-27902/? W/System: ClassLoader referenced unknown path: /data/app/com.example.andreas.drawing_exp-2/lib/arm64
05-31 21:10:41.433 27902-27902/? I/InstantRun: starting instant run server: is main process
05-31 21:10:41.450 27902-27902/? I/HwCust: Constructor found for class android.app.HwCustActivityImpl
05-31 21:10:41.465 27902-27902/? I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
05-31 21:10:41.477 27902-27902/? 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
05-31 21:10:41.533 27902-27913/? I/art: Background sticky concurrent mark sweep GC freed 2801(763KB) AllocSpace objects, 0(0B) LOS objects, 22% free, 3MB/4MB, paused 5.329ms total 13.242ms
05-31 21:10:41.567 27902-27902/? W/VRSystemServiceManager: vr service is not alive
05-31 21:10:41.568 27902-27902/? I/HwSecImmHelper: mSecurityInputMethodService is null
05-31 21:10:41.571 27902-27902/? I/HwPointEventFilter: support AFT
05-31 21:10:41.615 27902-27922/? I/OpenGLRenderer: Initialized EGL, version 1.4
05-31 21:10:41.621 27902-27922/? W/linker: /vendor/lib64/libhwuibp.so: unused DT entry: type 0xf arg 0xe3a
05-31 21:10:41.629 27902-27902/? W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
05-31 21:10:48.728 27902-27902/com.example.andreas.drawing_exp I/hwaps: JNI_OnLoad
05-31 21:10:48.802 27902-27902/com.example.andreas.drawing_exp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.andreas.drawing_exp, PID: 27902
java.lang.NullPointerException: Attempt to read from field 'boolean com.example.andreas.drawing_exp.CanvasView.colorRed' on a null object reference
at com.example.andreas.drawing_exp.MainActivity.onClick(MainActivity.java:37)
at android.view.View.performClick(View.java:5646)
at android.view.View$PerformClick.run(View.java:22473)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
05-31 21:10:48.837 27902-27902/com.example.andreas.drawing_exp I/Process: Sending signal. PID: 27902 SIG: 9
You are using invalidate() incorrectly.
This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().
You use postInvalidate() to do this.
I found out why my app crashes after watching a few tutorials on how to draw in a custom view in YouTube.
It is because I made the initialisation of my canvas view class the wrong way. I did not add an ID for the view and did not initialize with 'findViewById', instead I used the constructor of the class. But anyway, thanks for your answers!
Here is how the changed code looks like (short excerpt of original code):
public class MainActivity extends AppCompatActivity implements
View.OnClickListener{
CanvasView canvasView;
Button btnChangeColor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
canvasView = (CanvasView) findViewById(R.id.canvasview);
btnChangeColor = (Button) findViewById(R.id.button);
btnChangeColor.setOnClickListener(this);
canvasView.colorRed = false;
}

Recycler View updates when acticity resumed with Firebase Database android

I am trying to make a Blog App in android for my portfolio and I am having a problem. When I open the app the recycler view does not show anything but when I press the back button and open the app it updates the recycler view and this problem I am facing when running the app on real device I have tried running them in two emulators one is Nexus 5 and another Pixel 2 and they work fine and load the recycler view in first attempt only.
This is the activity's code:--
package raghuveer.singh.bhardwaj.blogapp;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import raghuveer.singh.bhardwaj.blogapp.Adapters.HomePostAdapter;
import raghuveer.singh.bhardwaj.blogapp.PostPackage.PostPOJO;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, HomePostAdapter.CustomItemClickListener {
public ArrayList<PostPOJO> mListOfPost = new ArrayList<>();
public ArrayList<String> topics = new ArrayList<>();
HomePostAdapter homePostAdapter;
private FirebaseAuth mAuth;
private Toolbar mToolbar;
private DrawerLayout mDrawer;
private NavigationView mNavView;
private RecyclerView mRecyclerView;
private ProgressBar mProgressBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mNavView = (NavigationView) findViewById(R.id.nav_view);
mRecyclerView = (RecyclerView) findViewById(R.id.mRecyclerView);
setSupportActionBar(mToolbar);
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.open, R.string.close);
mDrawer.setDrawerListener(drawerToggle);
drawerToggle.syncState();
mNavView.setNavigationItemSelectedListener(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
homePostAdapter = new HomePostAdapter(mListOfPost, MainActivity.this, MainActivity.this);
mRecyclerView.setAdapter(homePostAdapter);
mRecyclerView.setLayoutManager(linearLayoutManager);
mRecyclerView.setHasFixedSize(true);
}
#Override
protected void onStart() {
super.onStart();
Toast.makeText(this, "START", Toast.LENGTH_SHORT).show();
mListOfPost = new ArrayList<>();
topics = new ArrayList<>();
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference referenceTopic = database.getReference("Users").child(mAuth.getCurrentUser().getUid()).child("Topics");
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser != null) {
Toast.makeText(this, "Log inned with user " + currentUser.getEmail(), Toast.LENGTH_SHORT).show();
referenceTopic.orderByKey().addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot dsp : dataSnapshot.getChildren()) {
topics.add(String.valueOf(dsp.getValue(String.class)));
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
DatabaseReference referencePost = database.getReference("Posts");
referencePost.orderByKey().addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot dsp : dataSnapshot.getChildren()) {
Log.d(MainActivity.class.getSimpleName(), dsp.child("topic").getValue().toString());
Iterator<String> iterator = topics.iterator();
while (iterator.hasNext()) {
String str = iterator.next();
if (dsp.child("topic").getValue().equals(str)) {
PostPOJO postPOJO = dsp.getValue(PostPOJO.class);
mListOfPost.add(postPOJO);
}
}
mProgressBar.setVisibility(View.INVISIBLE);
homePostAdapter.updateData(mListOfPost);
homePostAdapter.notifyDataSetChanged();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
Intent intent = new Intent(this, SignUp.class);
startActivity(intent);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void signOut() {
mAuth.signOut();
Intent intent = new Intent(this, SignUp.class);
startActivity(intent);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.sign_out:
signOut();
}
return true;
}
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.Profile:
Intent profileIntent = new Intent(this, Profile.class);
startActivity(profileIntent);
break;
case R.id.Topics:
Intent topicsIntent = new Intent(this, Topics.class);
startActivity(topicsIntent);
break;
}
return false;
}
public void startPostActivity(View view) {
Intent intent = new Intent(this, Post.class);
startActivity(intent);
}
#Override
public void onItemClick(int position) {
Intent intent = new Intent(this, Post.class);
Bundle bundle = new Bundle();
bundle.putSerializable("POJO", homePostAdapter.mListOfPost.get(position));
intent.putExtras(bundle);
startActivity(intent);
}
}
This is recycler view's code:--
package raghuveer.singh.bhardwaj.blogapp.Adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import raghuveer.singh.bhardwaj.blogapp.PostPackage.PostPOJO;
import raghuveer.singh.bhardwaj.blogapp.R;
/**
* Created by Lenovo on 03-12-2017.
*/
public class HomePostAdapter extends RecyclerView.Adapter<HomePostAdapter.viewHolder> {
public ArrayList<PostPOJO> mListOfPost;
private Context context;
CustomItemClickListener listener;
public interface CustomItemClickListener {
public void onItemClick(int position);
}
public HomePostAdapter(ArrayList<PostPOJO> mListOfPost, Context context,CustomItemClickListener customItemClickListener) {
this.mListOfPost = mListOfPost;
this.context = context;
this.listener = customItemClickListener;
}
#Override
public viewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.post_item,parent,false);
final viewHolder mViewHolder = new viewHolder(view);
return mViewHolder;
}
#Override
public void onBindViewHolder(viewHolder holder, int position) {
PostPOJO postPOJO = mListOfPost.get(position);
holder.titleTextView.setText(postPOJO.getTitle());
holder.subTitleTextView.setText(postPOJO.getSub_title());
Boolean wasImageSet=false;
Iterator<String> iterator = postPOJO.grouped_elements.iterator();
while (iterator.hasNext()){
String str = iterator.next();
if(str.startsWith("URL::")){
Picasso.with(context)
.load(str.substring(5))
.into(holder.headerImage);
wasImageSet = true;
break;
}
}
if(wasImageSet==false){
holder.headerImage.setImageDrawable(context.getResources().getDrawable(R.drawable.emptyimage));
}
holder.bind(position);
}
public void updateData(ArrayList<PostPOJO> postPOJOS){
this.mListOfPost = postPOJOS;
}
#Override
public int getItemCount() {
return mListOfPost.size();
}
public class viewHolder extends RecyclerView.ViewHolder{
private ImageView headerImage;
private TextView titleTextView;
private TextView subTitleTextView;
public viewHolder(final View itemView) {
super(itemView);
headerImage = (ImageView)itemView.findViewById(R.id.headerImage);
titleTextView = (TextView)itemView.findViewById(R.id.title);
subTitleTextView = (TextView)itemView.findViewById(R.id.sub_title);
}
public void bind(final int position){
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
listener.onItemClick(position);
}
});
}
}
}
Log on emulator is:---
12-03 16:39:26.864 12822-12822/? I/zygote: Not late-enabling -Xcheck:jni (already on)
12-03 16:39:26.928 12822-12822/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
12-03 16:39:27.113 12822-12822/raghuveer.singh.bhardwaj.blogapp W/zygote: Skipping duplicate class check due to unrecognized classloader
12-03 16:39:27.115 12822-12822/raghuveer.singh.bhardwaj.blogapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
12-03 16:39:27.119 12822-12822/raghuveer.singh.bhardwaj.blogapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
12-03 16:39:27.122 12822-12822/raghuveer.singh.bhardwaj.blogapp I/BiChannelGoogleApi: [FirebaseAuth: ] No Fallback module; NOT setting up for lazy initialization
12-03 16:39:27.170 12822-12843/raghuveer.singh.bhardwaj.blogapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
12-03 16:39:27.179 12822-12843/raghuveer.singh.bhardwaj.blogapp I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
12-03 16:39:27.179 12822-12843/raghuveer.singh.bhardwaj.blogapp I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
12-03 16:39:27.207 12822-12822/raghuveer.singh.bhardwaj.blogapp D/FirebaseAuth: Notifying id token listeners about user ( sLZMm3S1o8TESyFjjy11mYEdVTG3 ).
12-03 16:39:27.245 12822-12822/raghuveer.singh.bhardwaj.blogapp D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
12-03 16:39:27.258 12822-12822/raghuveer.singh.bhardwaj.blogapp V/FA: Cancelling job. JobID: -2093232798
12-03 16:39:27.260 12822-12822/raghuveer.singh.bhardwaj.blogapp V/FA: Registered activity lifecycle callback
12-03 16:39:27.261 12822-12822/raghuveer.singh.bhardwaj.blogapp I/FirebaseInitProvider: FirebaseApp initialization successful
12-03 16:39:27.298 12822-12822/raghuveer.singh.bhardwaj.blogapp V/FA: onActivityCreated
12-03 16:39:27.329 12822-12846/raghuveer.singh.bhardwaj.blogapp V/FA: Collection enabled
12-03 16:39:27.330 12822-12846/raghuveer.singh.bhardwaj.blogapp V/FA: App package, google app id: raghuveer.singh.bhardwaj.blogapp, 1:967774314306:android:75a87ded59f6ecc8
12-03 16:39:27.346 12822-12846/raghuveer.singh.bhardwaj.blogapp I/FA: App measurement is starting up, version: 11717
12-03 16:39:27.346 12822-12846/raghuveer.singh.bhardwaj.blogapp I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
12-03 16:39:27.347 12822-12846/raghuveer.singh.bhardwaj.blogapp I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app raghuveer.singh.bhardwaj.blogapp
12-03 16:39:27.347 12822-12846/raghuveer.singh.bhardwaj.blogapp D/FA: Debug-level message logging enabled
12-03 16:39:27.400 12822-12846/raghuveer.singh.bhardwaj.blogapp V/FA: Connecting to remote service
12-03 16:39:27.493 12822-12846/raghuveer.singh.bhardwaj.blogapp V/FA: Connection attempt already in progress
12-03 16:39:27.525 12822-12822/raghuveer.singh.bhardwaj.blogapp I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
12-03 16:39:27.525 12822-12822/raghuveer.singh.bhardwaj.blogapp I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 6
12-03 16:39:27.571 12822-12822/raghuveer.singh.bhardwaj.blogapp W/zygote: Skipping duplicate class check due to unrecognized classloader
12-03 16:39:27.639 12822-12846/raghuveer.singh.bhardwaj.blogapp V/FA: Connection attempt already in progress
12-03 16:39:27.640 12822-12846/raghuveer.singh.bhardwaj.blogapp V/FA: Activity resumed, time: 17890383
12-03 16:39:27.662 12822-12846/raghuveer.singh.bhardwaj.blogapp I/FA: Tag Manager is not found and thus will not be used
12-03 16:39:27.665 12822-12846/raghuveer.singh.bhardwaj.blogapp D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-3708820839437256875}]
12-03 16:39:27.669 12822-12850/raghuveer.singh.bhardwaj.blogapp D/OpenGLRenderer: HWUI GL Pipeline
12-03 16:39:27.674 12822-12849/raghuveer.singh.bhardwaj.blogapp D/NetworkSecurityConfig: No Network Security Config specified, using platform default
12-03 16:39:27.687 12822-12822/raghuveer.singh.bhardwaj.blogapp D/FirebaseApp: Notifying auth state listeners.
12-03 16:39:27.689 12822-12822/raghuveer.singh.bhardwaj.blogapp D/FirebaseApp: Notified 1 auth state listeners.
12-03 16:39:27.757 12822-12850/raghuveer.singh.bhardwaj.blogapp I/OpenGLRenderer: Initialized EGL, version 1.4
12-03 16:39:27.757 12822-12850/raghuveer.singh.bhardwaj.blogapp D/OpenGLRenderer: Swap behavior 1
12-03 16:39:27.757 12822-12850/raghuveer.singh.bhardwaj.blogapp W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
12-03 16:39:27.757 12822-12850/raghuveer.singh.bhardwaj.blogapp D/OpenGLRenderer: Swap behavior 0
12-03 16:39:27.758 12822-12846/raghuveer.singh.bhardwaj.blogapp V/FA: Connection attempt already in progress
12-03 16:39:27.780 12822-12850/raghuveer.singh.bhardwaj.blogapp D/EGL_emulation: eglCreateContext: 0xa6f84540: maj 3 min 0 rcv 3
12-03 16:39:27.797 12822-12850/raghuveer.singh.bhardwaj.blogapp D/EGL_emulation: eglMakeCurrent: 0xa6f84540: ver 3 0 (tinfo 0xa6f833e0)
12-03 16:39:27.799 12822-12850/raghuveer.singh.bhardwaj.blogapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
12-03 16:39:27.799 12822-12850/raghuveer.singh.bhardwaj.blogapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
12-03 16:39:27.799 12822-12850/raghuveer.singh.bhardwaj.blogapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
12-03 16:39:27.799 12822-12850/raghuveer.singh.bhardwaj.blogapp E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
12-03 16:39:28.009 12822-12850/raghuveer.singh.bhardwaj.blogapp D/EGL_emulation: eglMakeCurrent: 0xa6f84540: ver 3 0 (tinfo 0xa6f833e0)
12-03 16:39:28.093 12822-12850/raghuveer.singh.bhardwaj.blogapp D/EGL_emulation: eglMakeCurrent: 0xa6f84540: ver 3 0 (tinfo 0xa6f833e0)
12-03 16:39:28.138 12822-12850/raghuveer.singh.bhardwaj.blogapp D/EGL_emulation: eglMakeCurrent: 0xa6f84540: ver 3 0 (tinfo 0xa6f833e0)
12-03 16:39:28.177 12822-12846/raghuveer.singh.bhardwaj.blogapp D/FA: Connected to remote service
12-03 16:39:28.178 12822-12846/raghuveer.singh.bhardwaj.blogapp V/FA: Processing queued up service tasks: 4
12-03 16:39:29.645 12822-12832/raghuveer.singh.bhardwaj.blogapp I/zygote: Do partial code cache collection, code=30KB, data=30KB
12-03 16:39:29.645 12822-12832/raghuveer.singh.bhardwaj.blogapp I/zygote: After code cache collection, code=29KB, data=30KB
12-03 16:39:29.645 12822-12832/raghuveer.singh.bhardwaj.blogapp I/zygote: Increasing code cache capacity to 128KB
12-03 16:39:29.669 12822-12850/raghuveer.singh.bhardwaj.blogapp D/EGL_emulation: eglMakeCurrent: 0xa6f84540: ver 3 0 (tinfo 0xa6f833e0)
12-03 16:39:30.871 12822-12822/raghuveer.singh.bhardwaj.blogapp D/MainActivity: Cooking
12-03 16:39:30.883 12822-12822/raghuveer.singh.bhardwaj.blogapp D/MainActivity: Programming
12-03 16:39:30.944 12822-12822/raghuveer.singh.bhardwaj.blogapp W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
12-03 16:39:31.061 12822-12832/raghuveer.singh.bhardwaj.blogapp I/zygote: Do partial code cache collection, code=34KB, data=54KB
12-03 16:39:31.063 12822-12832/raghuveer.singh.bhardwaj.blogapp I/zygote: After code cache collection, code=34KB, data=54KB
12-03 16:39:31.063 12822-12832/raghuveer.singh.bhardwaj.blogapp I/zygote: Increasing code cache capacity to 256KB
12-03 16:39:31.063 12822-12832/raghuveer.singh.bhardwaj.blogapp I/zygote: JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
12-03 16:39:31.063 12822-12832/raghuveer.singh.bhardwaj.blogapp I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
12-03 16:39:33.629 12822-12846/raghuveer.singh.bhardwaj.blogapp V/FA: Inactivity, disconnecting from the service
Log on real mobile is:--
12-03 16:41:11.099 2211-2211/? I/art: Late-enabling -Xcheck:jni
12-03 16:41:11.199 2211-2211/raghuveer.singh.bhardwaj.blogapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
12-03 16:41:11.203 2211-2211/raghuveer.singh.bhardwaj.blogapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
12-03 16:41:11.212 2211-2211/raghuveer.singh.bhardwaj.blogapp I/BiChannelGoogleApi: [FirebaseAuth: ] No Fallback module; NOT setting up for lazy initialization
12-03 16:41:11.222 2211-2211/raghuveer.singh.bhardwaj.blogapp D/FirebaseAuth: Notifying id token listeners about user ( sLZMm3S1o8TESyFjjy11mYEdVTG3 ).
12-03 16:41:11.223 2211-2232/raghuveer.singh.bhardwaj.blogapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
12-03 16:41:11.232 2211-2211/raghuveer.singh.bhardwaj.blogapp D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
12-03 16:41:11.242 2211-2232/raghuveer.singh.bhardwaj.blogapp I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
12-03 16:41:11.242 2211-2232/raghuveer.singh.bhardwaj.blogapp I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
12-03 16:41:11.260 2211-2211/raghuveer.singh.bhardwaj.blogapp V/FA: Registered activity lifecycle callback
12-03 16:41:11.261 2211-2211/raghuveer.singh.bhardwaj.blogapp I/FirebaseInitProvider: FirebaseApp initialization successful
12-03 16:41:11.283 2211-2235/raghuveer.singh.bhardwaj.blogapp V/FA: Collection enabled
12-03 16:41:11.284 2211-2235/raghuveer.singh.bhardwaj.blogapp V/FA: App package, google app id: raghuveer.singh.bhardwaj.blogapp, 1:967774314306:android:75a87ded59f6ecc8
12-03 16:41:11.285 2211-2235/raghuveer.singh.bhardwaj.blogapp I/FA: App measurement is starting up, version: 11717
12-03 16:41:11.286 2211-2235/raghuveer.singh.bhardwaj.blogapp I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
12-03 16:41:11.286 2211-2235/raghuveer.singh.bhardwaj.blogapp I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app raghuveer.singh.bhardwaj.blogapp
12-03 16:41:11.286 2211-2235/raghuveer.singh.bhardwaj.blogapp D/FA: Debug-level message logging enabled
12-03 16:41:11.299 2211-2211/raghuveer.singh.bhardwaj.blogapp 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
12-03 16:41:11.302 2211-2235/raghuveer.singh.bhardwaj.blogapp V/FA: Connecting to remote service
12-03 16:41:11.309 2211-2211/raghuveer.singh.bhardwaj.blogapp V/FA: onActivityCreated
12-03 16:41:11.309 2211-2235/raghuveer.singh.bhardwaj.blogapp V/FA: Connection attempt already in progress
12-03 16:41:11.462 2211-2211/raghuveer.singh.bhardwaj.blogapp I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
12-03 16:41:11.462 2211-2211/raghuveer.singh.bhardwaj.blogapp I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 6
12-03 16:41:11.476 2211-2211/raghuveer.singh.bhardwaj.blogapp W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
12-03 16:41:11.476 2211-2211/raghuveer.singh.bhardwaj.blogapp W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
12-03 16:41:11.526 2211-2235/raghuveer.singh.bhardwaj.blogapp V/FA: Connection attempt already in progress
12-03 16:41:11.526 2211-2235/raghuveer.singh.bhardwaj.blogapp V/FA: Activity resumed, time: 11707769
12-03 16:41:11.535 2211-2235/raghuveer.singh.bhardwaj.blogapp I/FA: Tag Manager is not found and thus will not be used
12-03 16:41:11.543 2211-2211/raghuveer.singh.bhardwaj.blogapp I/ViewRootImpl: CPU Rendering VSync enable = true
12-03 16:41:11.543 2211-2235/raghuveer.singh.bhardwaj.blogapp D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-7835563879800379359}]
12-03 16:41:11.546 2211-2241/raghuveer.singh.bhardwaj.blogapp D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
12-03 16:41:11.565 2211-2211/raghuveer.singh.bhardwaj.blogapp D/Atlas: Validating map...
12-03 16:41:11.574 2211-2211/raghuveer.singh.bhardwaj.blogapp D/FirebaseApp: Notifying auth state listeners.
12-03 16:41:11.574 2211-2211/raghuveer.singh.bhardwaj.blogapp D/FirebaseApp: Notified 1 auth state listeners.
12-03 16:41:11.577 2211-2211/raghuveer.singh.bhardwaj.blogapp I/ViewRootImpl: CPU Rendering VSync enable = true
12-03 16:41:11.633 2211-2235/raghuveer.singh.bhardwaj.blogapp V/FA: Connection attempt already in progress
12-03 16:41:11.638 2211-2241/raghuveer.singh.bhardwaj.blogapp I/Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8909_LA.BR.1.2.5_RB2__release_AU (I9d3821c5ab)
OpenGL ES Shader Compiler Version: E031.25.03.04
Build Date: 02/24/16 Wed
Local Branch: mybranch18408715
Remote Branch: quic/LA.BR.1.2.5_rb2.32
Local Patches: NONE
Reconstruct Branch: NOTHING
12-03 16:41:11.639 2211-2241/raghuveer.singh.bhardwaj.blogapp I/OpenGLRenderer: Initialized EGL, version 1.4
12-03 16:41:11.652 2211-2241/raghuveer.singh.bhardwaj.blogapp D/OpenGLRenderer: Enabling debug mode 0
12-03 16:41:11.945 2211-2235/raghuveer.singh.bhardwaj.blogapp D/FA: Connected to remote service
12-03 16:41:11.945 2211-2235/raghuveer.singh.bhardwaj.blogapp V/FA: Processing queued up service tasks: 4
12-03 16:41:13.556 2211-2211/raghuveer.singh.bhardwaj.blogapp I/ViewRootImpl: CPU Rendering VSync enable = true
12-03 16:41:13.633 2211-2241/raghuveer.singh.bhardwaj.blogapp V/RenderScript: Application requested CPU execution
12-03 16:41:13.640 2211-2241/raghuveer.singh.bhardwaj.blogapp V/RenderScript: 0xb7a6a9d8 Launching thread(s), CPUs 4
12-03 16:41:14.419 2211-2211/raghuveer.singh.bhardwaj.blogapp D/MainActivity: Cooking
12-03 16:41:14.421 2211-2211/raghuveer.singh.bhardwaj.blogapp D/MainActivity: Programming
12-03 16:41:14.433 2211-2211/raghuveer.singh.bhardwaj.blogapp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy#f2c1b9f time:11295907
12-03 16:41:17.363 2211-2235/raghuveer.singh.bhardwaj.blogapp V/FA: Inactivity, disconnecting from the service
Try removing onStart method and copy the entire code to onCreate method.
OnStart is called several time during a lifecycle but onCreate is created once. So, you would want to put those firebase code in onCreate.
Its working on back button pressed and reopening the app because that's when onStart is called again.
I solved the problem through two steps:-
1)I moved the code of updating the recyclerview in oncreate.
2)I perfromed the post query i have completed populating the topic array list by pasting the post query and recycler view updation code after the for loop of data snapshot in ondatachange of topic query.
Yeah its bit confusing to explain.

Android - MediaPlayer : How to separating fastForward to another method (that later will be call)?

Here's my snippets :
public class MainActivity extends AppCompatActivity {
private int seekForwardTime = 5000;
private int seekBackwardTime = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekForward.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick (View v) {
Toast.makeText(getApplicationContext(), "Seek Forward music", Toast.LENGTH_SHORT).show();
forwardSong(mediaPlayer);
}
});
}
public void forwardSong(MediaPlayer mediaPlayer) {
int currentPosition = mediaPlayer.getCurrentPosition();
String tag2 = "currentPosition";
Log.v(tag2, String.valueOf(mediaPlayer.getCurrentPosition()));
if (currentPosition + seekForwardTime <= mediaPlayer.getCurrentPosition()) {
mediaPlayer.seekTo(currentPosition + seekForwardTime);
} else {
String tag = "main activity";
Log.v(tag, "else state");
mediaPlayer.seekTo(mediaPlayer.getDuration());
}
}
}
As per title, I want to separate Fast Forward (seek 5 second forward for each press) behavior from seekForward.OnClickListener to another method (forwardSong).
But, when I trigger seekForward, instead of seeking, it kills mediaPlayer. So I have to press 'play' button again and start from beginning of song.
Am I missed something? I'm happy to receive any solution and/or advice.
ps : please ignore the Log statement, I'm just do some test before.
Thanks!
Edit - 09/08/2017
As requested, here's the logcat
08-09 16:36:01.688 2707-2707/? I/art: Not late-enabling -Xcheck:jni (already on)
08-09 16:36:01.688 2707-2707/? W/art: Unexpected CPU variant for X86 using defaults: x86
08-09 16:36:01.781 2707-2707/? W/System: ClassLoader referenced unknown path: /data/app/com.example.android.musicplayer-2/lib/x86
08-09 16:36:01.791 2707-2707/? I/InstantRun: starting instant run server: is main process
08-09 16:36:01.856 2707-2707/? 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
08-09 16:36:02.094 2707-2707/com.example.android.musicplayer D/MediaPlayer: setSubtitleAnchor in MediaPlayer
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer I/OpenGLRenderer: Initialized EGL, version 1.4
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer D/OpenGLRenderer: Swap behavior 1
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
08-09 16:36:02.189 2707-2730/com.example.android.musicplayer D/OpenGLRenderer: Swap behavior 0
08-09 16:36:02.219 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglCreateContext: 0xa1328e80: maj 2 min 0 rcv 2
08-09 16:36:02.264 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:36:02.333 2707-2707/com.example.android.musicplayer W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
08-09 16:36:02.343 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:47.717 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:47.747 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:48.672 2707-2707/com.example.android.musicplayer V/currentPosition: 707
08-09 16:58:48.673 2707-2707/com.example.android.musicplayer V/main activity: else state
08-09 16:58:49.669 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:50.684 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:51.667 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
08-09 16:58:53.631 2707-2730/com.example.android.musicplayer D/EGL_emulation: eglMakeCurrent: 0xa1328e80: ver 2 0 (tinfo 0xa1320a20)
I'm confused. Why it entering else statement?
Modify your forwardSong function the following way :
public void forwardSong(MediaPlayer mediaPlayer) {
int currentPosition = mediaPlayer.getCurrentPosition();
String tag2 = "currentPosition";
Log.v(tag2, String.valueOf(mediaPlayer.getCurrentPosition()));
if (currentPosition + seekForwardTime <= mediaPlayer.getDuration()) {
mediaPlayer.seekTo(currentPosition + seekForwardTime);
} else {
String tag = "main activity";
Log.v(tag, "else state");
mediaPlayer.seekTo(mediaPlayer.getDuration());
}
}
The following condition is the problem, it will be always false and the mediaplayer will always seek to the end of your media file because of your else statement.
if (currentPosition + seekForwardTime <= mediaPlayer.getCurrentPosition())

Categories