Improve Java code to be executed faster on Android The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceIs Java “pass-by-reference” or “pass-by-value”?Does a finally block always get executed in Java?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?Improve INSERT-per-second performance of SQLite?Creating a memory leak with JavaWhy are elementwise additions much faster in separate loops than in a combined loop?Why is it faster to process a sorted array than an unsorted array?Is < faster than <=?Proper use cases for Android UserManager.isUserAGoat()?
Why doesn't a hydraulic lever violate conservation of energy?
How do spell lists change if the party levels up without taking a long rest?
Simulating Exploding Dice
Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?
Does Parliament need to approve the new Brexit delay to 31 October 2019?
Is every episode of "Where are my Pants?" identical?
Why did Peik Lin say, "I'm not an animal"?
Are spiders unable to hurt humans, especially very small spiders?
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
Example of compact Riemannian manifold with only one geodesic.
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
Single author papers against my advisor's will?
Huge performance difference of the command find with and without using %M option to show permissions
When did F become S? Why?
How many cones with angle theta can I pack into the unit sphere?
Why can't devices on different VLANs, but on the same subnet, communicate?
What is the padding with red substance inside of steak packaging?
My body leaves; my core can stay
Is 'stolen' appropriate word?
Deal with toxic manager when you can't quit
How to read αἱμύλιος or when to aspirate
Homework question about an engine pulling a train
Can the DM override racial traits?
How to make Illustrator type tool selection automatically adapt with text length
Improve Java code to be executed faster on Android
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceIs Java “pass-by-reference” or “pass-by-value”?Does a finally block always get executed in Java?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?Improve INSERT-per-second performance of SQLite?Creating a memory leak with JavaWhy are elementwise additions much faster in separate loops than in a combined loop?Why is it faster to process a sorted array than an unsorted array?Is < faster than <=?Proper use cases for Android UserManager.isUserAGoat()?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
My Java code is executing really slowly in my Android device. I think it's because I made it all in one class. I need some recommendations for how to improve my code, maybe by dividing it into different classes. How you would do it?
public class MainActivity extends AppCompatActivity
View white;
Animation downtoup;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Remove notification bar
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
//MovingScanSquare
white = findViewById(R.id.white);
downtoup = AnimationUtils.loadAnimation(this, R.anim.downtoup);
white.setVisibility(View.VISIBLE);
downtoup = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 1.1f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.f);
downtoup.setDuration(2200);
downtoup.setRepeatCount(-1);
downtoup.setRepeatMode(Animation.REVERSE);
downtoup.setInterpolator(new LinearInterpolator());
white.setAnimation(downtoup);
//movingscreen
final ImageView backgroundOne = findViewById(R.id.background_one);
final ImageView backgroundTwo = findViewById(R.id.background_two);
final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, -1.0f);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(3000L);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
@Override
public void onAnimationUpdate(ValueAnimator animation)
final float progress = (float) animation.getAnimatedValue();
final float width = backgroundOne.getWidth();
final float translationX = width * progress;
backgroundOne.setTranslationX(translationX);
backgroundTwo.setTranslationX(translationX + width);
);
animator.start();
java android performance
add a comment |
My Java code is executing really slowly in my Android device. I think it's because I made it all in one class. I need some recommendations for how to improve my code, maybe by dividing it into different classes. How you would do it?
public class MainActivity extends AppCompatActivity
View white;
Animation downtoup;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Remove notification bar
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
//MovingScanSquare
white = findViewById(R.id.white);
downtoup = AnimationUtils.loadAnimation(this, R.anim.downtoup);
white.setVisibility(View.VISIBLE);
downtoup = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 1.1f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.f);
downtoup.setDuration(2200);
downtoup.setRepeatCount(-1);
downtoup.setRepeatMode(Animation.REVERSE);
downtoup.setInterpolator(new LinearInterpolator());
white.setAnimation(downtoup);
//movingscreen
final ImageView backgroundOne = findViewById(R.id.background_one);
final ImageView backgroundTwo = findViewById(R.id.background_two);
final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, -1.0f);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(3000L);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
@Override
public void onAnimationUpdate(ValueAnimator animation)
final float progress = (float) animation.getAnimatedValue();
final float width = backgroundOne.getWidth();
final float translationX = width * progress;
backgroundOne.setTranslationX(translationX);
backgroundTwo.setTranslationX(translationX + width);
);
animator.start();
java android performance
Splitting the code in several classes could improve readability, but I fail to see how it would improve performance.
– Maurice Perry
Mar 22 at 5:46
add a comment |
My Java code is executing really slowly in my Android device. I think it's because I made it all in one class. I need some recommendations for how to improve my code, maybe by dividing it into different classes. How you would do it?
public class MainActivity extends AppCompatActivity
View white;
Animation downtoup;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Remove notification bar
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
//MovingScanSquare
white = findViewById(R.id.white);
downtoup = AnimationUtils.loadAnimation(this, R.anim.downtoup);
white.setVisibility(View.VISIBLE);
downtoup = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 1.1f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.f);
downtoup.setDuration(2200);
downtoup.setRepeatCount(-1);
downtoup.setRepeatMode(Animation.REVERSE);
downtoup.setInterpolator(new LinearInterpolator());
white.setAnimation(downtoup);
//movingscreen
final ImageView backgroundOne = findViewById(R.id.background_one);
final ImageView backgroundTwo = findViewById(R.id.background_two);
final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, -1.0f);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(3000L);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
@Override
public void onAnimationUpdate(ValueAnimator animation)
final float progress = (float) animation.getAnimatedValue();
final float width = backgroundOne.getWidth();
final float translationX = width * progress;
backgroundOne.setTranslationX(translationX);
backgroundTwo.setTranslationX(translationX + width);
);
animator.start();
java android performance
My Java code is executing really slowly in my Android device. I think it's because I made it all in one class. I need some recommendations for how to improve my code, maybe by dividing it into different classes. How you would do it?
public class MainActivity extends AppCompatActivity
View white;
Animation downtoup;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Remove notification bar
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
//MovingScanSquare
white = findViewById(R.id.white);
downtoup = AnimationUtils.loadAnimation(this, R.anim.downtoup);
white.setVisibility(View.VISIBLE);
downtoup = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 1.1f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.f);
downtoup.setDuration(2200);
downtoup.setRepeatCount(-1);
downtoup.setRepeatMode(Animation.REVERSE);
downtoup.setInterpolator(new LinearInterpolator());
white.setAnimation(downtoup);
//movingscreen
final ImageView backgroundOne = findViewById(R.id.background_one);
final ImageView backgroundTwo = findViewById(R.id.background_two);
final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, -1.0f);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(3000L);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
@Override
public void onAnimationUpdate(ValueAnimator animation)
final float progress = (float) animation.getAnimatedValue();
final float width = backgroundOne.getWidth();
final float translationX = width * progress;
backgroundOne.setTranslationX(translationX);
backgroundTwo.setTranslationX(translationX + width);
);
animator.start();
java android performance
java android performance
edited Mar 22 at 5:59
karel
2,32782732
2,32782732
asked Mar 22 at 5:43
Braulio TrujilloBraulio Trujillo
11
11
Splitting the code in several classes could improve readability, but I fail to see how it would improve performance.
– Maurice Perry
Mar 22 at 5:46
add a comment |
Splitting the code in several classes could improve readability, but I fail to see how it would improve performance.
– Maurice Perry
Mar 22 at 5:46
Splitting the code in several classes could improve readability, but I fail to see how it would improve performance.
– Maurice Perry
Mar 22 at 5:46
Splitting the code in several classes could improve readability, but I fail to see how it would improve performance.
– Maurice Perry
Mar 22 at 5:46
add a comment |
2 Answers
2
active
oldest
votes
Splitting the code into different classes won't get you so far. And it's quite difficult to say what's going on there without profiling it. Use one of the profiling tools, VisualVM for example, to do that.
Monitor your application, find out which line of code takes too much time and try to optimize it.
add a comment |
To improve readability you can use different classes. But it will not improve performance much.
For long processing task use background thread instead of doing it on the main thread.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293538%2fimprove-java-code-to-be-executed-faster-on-android%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Splitting the code into different classes won't get you so far. And it's quite difficult to say what's going on there without profiling it. Use one of the profiling tools, VisualVM for example, to do that.
Monitor your application, find out which line of code takes too much time and try to optimize it.
add a comment |
Splitting the code into different classes won't get you so far. And it's quite difficult to say what's going on there without profiling it. Use one of the profiling tools, VisualVM for example, to do that.
Monitor your application, find out which line of code takes too much time and try to optimize it.
add a comment |
Splitting the code into different classes won't get you so far. And it's quite difficult to say what's going on there without profiling it. Use one of the profiling tools, VisualVM for example, to do that.
Monitor your application, find out which line of code takes too much time and try to optimize it.
Splitting the code into different classes won't get you so far. And it's quite difficult to say what's going on there without profiling it. Use one of the profiling tools, VisualVM for example, to do that.
Monitor your application, find out which line of code takes too much time and try to optimize it.
answered Mar 22 at 6:18
Pavel SmirnovPavel Smirnov
2,367818
2,367818
add a comment |
add a comment |
To improve readability you can use different classes. But it will not improve performance much.
For long processing task use background thread instead of doing it on the main thread.
add a comment |
To improve readability you can use different classes. But it will not improve performance much.
For long processing task use background thread instead of doing it on the main thread.
add a comment |
To improve readability you can use different classes. But it will not improve performance much.
For long processing task use background thread instead of doing it on the main thread.
To improve readability you can use different classes. But it will not improve performance much.
For long processing task use background thread instead of doing it on the main thread.
answered Mar 22 at 6:10
MagudeshMagudesh
15818
15818
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293538%2fimprove-java-code-to-be-executed-faster-on-android%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Splitting the code in several classes could improve readability, but I fail to see how it would improve performance.
– Maurice Perry
Mar 22 at 5:46