From some reason my app runs in a very laggy way on my new s7 edge but works fine on my old onePlus 2. They both run 6.0.1. I followed this answer but it didn't fix the problems. I checked Memory monitor and saw it allocates 255mb!! and i'm not doing any calculations or using a lot of Bitmaps
.
Is there a way to see what is running on the UI Thread?
Is someone familiar with this problem and can help me?
EDIT- SOLUTION:
So apparently some devices struggle to handle images that are loaded via the xml. I set a background image in the MainActivity
and that was the reason the app was so laggy. I also did it in the RecycleView
and even when it was the same small image in every item
it made the app run in a laggy way.
The way to fix this is to set all images dynamically from the code. I used Picasso
for that like shown. here
main
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(notLoggedIn()) {
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
}
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycle_view);
recyclerView.setAdapter(new RecycleViewPostsAdapter(MainActivity.this));
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
login
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_login);
AppEventsLogger.activateApp(this);
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("email");
mPasswordView = (EditText) findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == R.id.login || id == EditorInfo.IME_NULL) {
attemptLogin();
return true;
}
return false;
}
});
final TextView register = (TextView) findViewById(R.id.textView2);
Button mEmailSignInButton = (Button) findViewById(R.id.sign_in_button);
mEmailSignInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
attemptLogin();
}
});
register.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), registerActivity.class));
}
});
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
}
recycleview
@Override
public void onBindViewHolder(PostsVH holder, int position) {
switch (position % 5){
case 0:
Picasso.with(context).load(R.mipmap.profile1).into(holder.profilePic);
...