This is the code that I used:
Intent i = new Intent(PSTimelineActivity.this, PSPreCheckoutActivity.class);
i.putExtra("checkout", 0);
startActivity(i);
And it takes around 5-6 seconds to change the activity. Time in which my console log is flooded by the same error, tens of times:
09-10 15:56:16.661 31171-31189/nl.hgrams.passenger W/Binder﹕ Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException: Attempt to read from field 'android.view.HardwareRenderer android.view.View$AttachInfo.mHardwareRenderer' on a null object reference
at android.view.WindowManagerGlobal.dumpGfxInfo(WindowManagerGlobal.java:476)
at android.app.ActivityThread$ApplicationThread.dumpGfxInfo(ActivityThread.java:1086)
at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:546)
at android.os.Binder.execTransact(Binder.java:446)
TRACEVIEW doesn't help, because of the services that work in the background of the app.
I added some logs, for the next Activity, at the start and end of OnCreate()
and OnResume()
, and it enters here, logs them, and only after, I get flooded by the error. And the View
comes to the screen only after the errors finish. Which is weird. because at OnResume()
I should have had the view already correct?
09-10 16:16:45.722 18674-18674/nl.hgrams.passenger I/﹕ BINDER here started activity
09-10 16:16:45.798 18674-18674/nl.hgrams.passenger I/﹕ BINDER onCreate 1
09-10 16:16:45.813 18674-18674/nl.hgrams.passenger I/﹕ BINDER onCreate 2
09-10 16:16:45.819 18674-18674/nl.hgrams.passenger I/﹕ BINDER onResume 1
09-10 16:16:45.836 18674-18674/nl.hgrams.passenger I/﹕ BINDER onResume 2
09-10 16:16:45.914 18674-18857/nl.hgrams.passenger W/Binder﹕ Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException: Attempt to read from field 'android.view.HardwareRenderer android.view.View$AttachInfo.mHardwareRenderer' on a null object reference
at android.view.WindowManagerGlobal.dumpGfxInfo(WindowManagerGlobal.java:476)
at android.app.ActivityThread$ApplicationThread.dumpGfxInfo(ActivityThread.java:1086)
at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:546)
at android.os.Binder.execTransact(Binder.java:446)
The error might be in my OnCreate()
function, even something might be called on a separate thread
and that causes the error.
This is my OnCreate()
function, if it helps:
http://pastebin.com/1ajdzSr2
EDIT: After some more test, I figured out that it hangs on the init function that I call from my OnResume()
method.
My onResume()
:
@Override
protected void onResume() {
super.onResume();
CheckOutIntent cot = PSLocationCenter.getInstance().pref.getOutIntent(PSPreCheckoutActivity.this);
if( cot != null){
Intent intent = new Intent(PSPreCheckoutActivity.this, PSTimelineActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
PSLocationCenter.getInstance().pref.setIsBackground(this, false);
if(!PSLocationCenter.getInstance().mLocationClient.isConnected()) {
PSLocationCenter.getInstance().startLocationClient();
}
init();
}
NOW this is my init()
Function:
I created it specially in a AsyncTask, to that it won't use the UI Thread.
BUT inside, at a moment, I use realm, which must be on the main thread, so I make a Handler post. Might this be the problem? I'm still debugging , but I'm guessing it might be there.
PS: Will it help if I remove the Asynctask?
public void init(){
loader.setVisibility(View.VISIBLE);
findViewById(R.id.subheader).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
closeSearchKeyboard();
}
});
AsyncTask initAsync = new AsyncTask() {
@Override
protected Object doInBackground(Object[] params) {
if(checkout == 2){
Log.i("","PSPreCheckoutActivity checkout 2");
if(PSLocationCenter.getInstance().mLocationClient.isConnected()){
try {
Geocoder geocoder = new Geocoder(PSPreCheckoutActivity.this, Locale.getDefault());
List<Address> address = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
if (address.size() > 0) {
if(tripName != null){
currentPlace = new Destination("google", null, null, null, tripName, loc.getLongitude(), loc.getLatitude() , (String.format(address.get(0).getMaxAddressLineIndex() > 0 ? address.get(0).getAddressLine(0) : "") + ", " + address.get(0).getLocality()), false, false, null);
}else{
currentPlace = new Destination("google", null, null, null, String.format(address.get(0).getMaxAddressLineIndex() > 0 ? address.get(0).getAddressLine(0) : ""), loc.getLongitude(), loc.getLatitude() , (String.format(address.get(0).getMaxAddressLineIndex() > 0 ? address.get(0).getAddressLine(0) : "") + ", " + address.get(0).getLocality()), false, false, null);
}
}
WillGetNearestData();
}catch (Exception e){
currentPlace = new Destination("nointerneterror", null, null, null, "nointerneterror", 0,0 , "nointerneterror", false, false, null);
WillGetNearestData();
Log.i("", "precheckout error: " + e.getMessage());
Utils.appendLog("precheckout error: " + e.getMessage());
if(e.getMessage().contains("Timed out")){
AlertDialog.show(PSPreCheckoutActivity.this, getString(R.string.Error), e.getMessage(), getString(R.string.OK), null);
}
}
}else{
try {
PSLocationCenter.getInstance().startLocationClient();
Thread.sleep(1000);
init();
}catch (Exception e){
Log.e("", "precheckout init error is: " + e.getMessage());
if(e.getMessage().contains("Timed out")){
AlertDialog.show(PSPreCheckoutActivity.this, getString(R.string.Error), e.getMessage(), getString(R.string.OK), null);
}
init();
}
}
}else{
Log.i("","PSPreCheckoutActivity checkout not 2");
Handler han = new Handler(Looper.getMainLooper());
han.post(new Runnable() {
@Override
public void run() {
PSTrip psTrip = PSTripDBFactory.getInstance(PSPreCheckoutActivity.this).getActiveTrip();
if(psTrip != null){
Destination destination = psTrip.getDestination();
LatLng finishLocation = new LatLng(PSLocationCenter.getInstance().locEnd.getLatitude(), PSLocationCenter.getInstance().locEnd.getLongitude());
if(destination != null) {
isRoaming = false;
finishLocation = new LatLng(psTrip.getDestination().getLat(), psTrip.getDestination().getLon());
}else{
isRoaming = true;
}
if(PSLocationCenter.getInstance().mLocationClient.isConnected()){
if(checkout != 2){
loc = new Location("");
loc.setLatitude(LocationServices.FusedLocationApi.getLastLocation(PSLocationCenter.getInstance().mLocationClient).getLatitude());
loc.setLongitude(LocationServices.FusedLocationApi.getLastLocation(PSLocationCenter.getInstance().mLocationClient).getLongitude());
}
try {
Geocoder geocoder = new Geocoder(PSPreCheckoutActivity.this, Locale.getDefault());
List<Address> address = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
if (address.size() > 0) {
if(tripName != null){
currentPlace = new Destination("google", null, null, null, tripName, loc.getLongitude(), loc.getLatitude() , (String.format(address.get(0).getMaxAddressLineIndex() > 0 ? address.get(0).getAddressLine(0) : "") + ", " + address.get(0).getLocality()), false, false, null);
}else{
currentPlace = new Destination("google", null, null, null, String.format(address.get(0).getMaxAddressLineIndex() > 0 ? address.get(0).getAddressLine(0) : ""), loc.getLongitude(), loc.getLatitude() , (String.format(address.get(0).getMaxAddressLineIndex() > 0 ? address.get(0).getAddressLine(0) : "") + ", " + address.get(0).getLocality()), false, false, null);
}
}
}catch (Exception e){
Log.i("","precheckout error: " + e.getMessage());
Utils.appendLog("precheckout error: " + e.getMessage());
}
LatLng locLatLng = new LatLng(loc.getLatitude(), loc.getLongitude());
if(Utils.distanceBetween2Points(locLatLng, finishLocation) < 250 && !isRoaming){ //TODO will have to be 250, now 9000 for hardcoded values to be seen all the time
isNearby = true;
plannedDestination = destination;
}
WillGetNearestData();
}else{
try {
PSLocationCenter.getInstance().startLocationClient();
Thread.sleep(1000);
init();
}catch (Exception e){
Log.e("","precheckout init 2 error is: " + e.getMessage());
init();
}
}
}
}
});
}
return null;
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
}
};
initAsync.execute();
}
Thanks to @Ci_ I found out the issue. This is apparently a bug of Android Studio 1.4 Preview. or the Android SDK. For more details, check here: Android: Constant memory consumption / dumpGfxInfo() That helped me resolve it