Problem
Hello all, I've come across a very problematic issue/bug with ADB or Android Studio or both.
So I have my android phone connected via USB with USB Debugging enabled testing my app. I had added a few functions and wanted to test them (two problematic activities), so I went ahead and ran it. Upon clicking the navigation icon to start a new activity, the screen dimmed a bit, and after about 30 seconds, the entire screen was white with the exception of the native android dropdown menu at the top still visible.
I went ahead and tried to 'Stop' the app, at which point the android studio froze. By running a series of commands (as I later discovered) or by simply closing adb.exe
in the task manager, android studio resumed operation but disconnected from the device of course. My device however, had to do a full reboot as it seems the entire system was bogged down with some issue and would take 10x the usual time to open another app.
Testing
Upon retesting I noticed a few things
- My
logcat
would print this over and over for about 30 times or more
Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.monkeyPatchExistingResources
Could not find class 'android.util.ArrayMap', referenced from method com.android.tools.fd.runtime.MonkeyPatcher.pruneResourceCache
IO Error creating local socket at church.rmhymnal
java.io.IOException: Address already in use
at android.net.LocalSocketImpl.bindLocal(Native Method)
at ........
- Upon running the command
netstat -o -n -a | findstr 5037
in command prompt, I would see a massive list of TCP ports that had been apparantly opened repeatedly. (Some of those with TIME_WAIT would eventually be marked as ESTABLISHED
Code
I'm not sure what could be causing the issue but I'll drop the code for the activity I am calling, as well as the calling method below.
Calling function in Main Activity
Intent intent = new Intent(HomescreenActivity.this, IndexActivity.class);
Parcelable wrapped = Parcels.wrap(songs);
intent.putExtra("songs", wrapped);
startActivity(intent);
IndexActivity.java (Activity to be called)
public class IndexActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
DrawerLayout drawer;
LinearLayout ll;
NavigationView navigationView;
ArrayList<Song> songs;
int index;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_index);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view_index);
if (navigationView != null) {
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_index);
}
Intent intent = getIntent();
songs = Parcels.unwrap(intent.getParcelableExtra("songs"));
ll = (LinearLayout) findViewById(R.id.indexButtonView);
index = 0;
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
listIndex();
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.index, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
super.finish();
} else if (id == R.id.nav_hymns) {
Intent intent = new Intent(IndexActivity.this, SongDisplayActivity.class);
Parcelable wrapped = Parcels.wrap(songs);
intent.putExtra("songs", wrapped);
intent.putExtra("index", index);
startActivity(intent);
} else if (id == R.id.nav_index) {
//Do nothing
} else if (id == R.id.nav_settings) {
Intent intent = new Intent(IndexActivity.this, SettingsActivity.class);
startActivity(intent);
} else if (id == R.id.nav_about) {
//Unimplemented
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
public void listIndex() {
for (int i = 0; i < songs.size(); ++i)
{
if (!songs.get(i).getTitle().equals("")) {
final Button songButton = new Button(this);
songButton.setText(String.format("%s - %s", songs.get(i).getNumber(), songs.get(i).getTitle()));
songButton.setBackgroundResource(R.drawable.buttonshadowbg);
songButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
songButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
index = songButton.getText().charAt(0);
Intent intent = new Intent(IndexActivity.this, SongDisplayActivity.class);
Parcelable wrapped = Parcels.wrap(songs);
intent.putExtra("songs", wrapped);
intent.putExtra("index", index);
startActivity(intent);
}
});
songButton.setGravity(Gravity.CENTER_HORIZONTAL);
ll.addView(songButton);
}
}
}
}
Clarifications
All the methods before I created listIndex()
had worked perfectly. However after adding it as well as a few other methods in a different activity, it never worked since.
Final Thoughts
- Is it a problem related to my code or is it an issue with my adb or android studio?
- Could the issue be brought about by some error in another class that's not called in this particular method?
Any ideas leading to a possible solution would be highly appreciated, as my ability to develop and test is slowed greatly since I have to restart the testing device 9 times out of 10.