I am a beginner in Android application development.
I've been working on Android Studio 2.0, and I've been testing the actual machine on Android.4.1.2 (API16).
There was no particular problem and it worked smoothly.
After a certain amount of completion, we tested the actual machine with Android.6.0.1 (API23).
Then, the movement gets rough and doesn't work properly.
The keystrokes are unresponsive and cannot be typed.
API16 has tried both HTC and xperia tablets, and both are fine.
API 23 tried xperia x and DIGNO, and both were not allowed.
I'm at a loss because I don't know why the above situation occurs.
I would appreciate it if you could tell me what the possibilities are.
Thank you for your cooperation.
As a specific part of the defect, when the motion is performed, especially when other actions, sound effects, etc., are overlapped, it becomes NG.
Also, the image using timer.schedule has been replaced and the frame has dropped.
SoundPool is used for sound effects.
Any hint would be helpful.Thank you for your cooperation.
Main text excerpt
// Load and set music
p=MediaPlayer.create(getApplicationContext(), R.raw.s_m_map01);
p.setLooping(true); // Continuous playback ON
p.setVolume (0.4f, 0.4f);
// Sound effects settings
sp=new SoundPool(3,AudioManager.STREAM_MUSIC,0);
sound_id[0] = sp.load(this, R.raw.s_s_map00,1);
sound_id[1] = sp.load(this, R.raw.s_s_map01,1);
sound_id[2] = sp.load(this, R.raw.s_s_map02,1);
// Periodic Run Start (Basic 0.175 seconds)
timer.schedule(anim,0L,175L);
// Run every 0.175 seconds*************************************
TimerTaskanim=new TimerTask(){
public void run() {
if(App.power==0&power_0==true){
power_0=false;
} else {
power_0 = true; // Once power is lost, it will be processed twice
if(kyara_i_t!=0){
// Go to run animation or running -------------------------
hdl.post(newkyara_i_jikkou()); // Go Run
} else if ((ImageView) findViewById(R.id.map_b1)).isPressed()||(ImageView) findViewById(R.id.map_b2)).isPressed()|(ImageView) findViewById(R.id.map_b3)).isPressed()|(ImageView) findViewById(R.id.map_b3)).isPressed(ap)|((ImageView) findView_By(mapId( .))
// If the key is pressed for a long time without moving -----------------------------
if(input==1){
kyara_i_t=1;
if(((ImageView)findViewById(R.id.map_b1)).isPressed())kyara_i=1;
if(((ImageView)findViewById(R.id.map_b2)).isPressed())kyara_i=2;
if(((ImageView)findViewById(R.id.map_b3)).isPressed())kyara_i=3;
if(((ImageView)findViewById(R.id.map_b4)).isPressed())kyara_i=4;
hdl.post(newkyara_i_jikkou()); // Go Run
}
} else{
// If nothing has been done, step-by-step ---------------------
hdl.post(newkyara_anim()); // Stepping
}
}
}
};
// Execute character animation (step) ********************************************************************************************************
class kyara_animplementations Runnable {
public void run() {
// Change to character foot image
inti;
kyara_anim++;
if(kyara_anim==5)kyara_anim=1;
if(kyara_anim==4)i=2;
else i=kyara_anim;
img_id = "kyara";
img_file="kyara_"+kyara_no+"_"+kyara_m+"_"+i;
img_img(img_file, img_id);
}
}
Here are some excerpts.I don't know if it will be affected, but
Thank you.
(It's my first Android program, and it's dirty, but please take care of it.)
Thank you very much for your reply.It is helpful.
I changed it to the program you gave me right away, but the situation was not improved.
In addition, I will answer your questions.
About img_img
private void img_img(String img_file2, String img_id2){
// Image change img (image data, which name?) **************************************************************************************************************************************************
String[]stArrayData=img_file2.split("\\.");
intmon_id = getResources().getIdentifier(stArrayData[0], "drawable", getPackageName()); // Retrieve resources
String[]stArrayData2 = img_id2.split("\\.");
intmon_id2=getResources().getIdentifier(stArrayData2[0], "id", getPackageName()); // Retrieve resources
((ImageView) findViewById(mon_id2)).setImageResource(mon_id);
}
It is a program to switch between images.
About CPU Monitors
Android 6.0= CPU is around 30%.
Android 4.1= CPU is around 1%.
There is a big difference.
About GPU Monitors
Android 6.0=
The Swap Buffers are truncated to 100-200 ms.
Sometimes the Misc Time is over 10 ms.
Is it because the image was not loaded in advance?
Android 4.1=
Could you show it to me?
Additional Memory
Android 6.0= CPU is around 250MB.
Android 4.1= CPU is around 120MB.
Is it because of the difference in resolution?
I'm curious that the numbers are big.
The file size during installation is approximately 30MB.
We apologize for the inconvenience and appreciate your cooperation.
Note: **********************************************************
Since Android 4.1 works normally, I wonder if there is something wrong with the initial setup.
"I thought about it, but is the ""build.gradle"" below irrelevant?"
クラス Class
buildscript{
repositories {
jcenter()
}
dependencies {
classpath'com.android.tools.build:gradle:2.0.0'
// NOTE: Do not place your application dependencies here; they Belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean (type: Delete) {
delete rootProject.buildDir
}
appapp
apply plugin: 'com.android.application'
android{android{
compileSdkVersion23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "***********************"
minSdkVersion15
targetSdkVersion23
versionCode1
versionName "1.0"
}
buildTypes {
release {
miniEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// addition
applicationVariants.all {variant->
if(variant.buildType.name.equals("release"){
variant.outputs.each {output->
if(output.outputFile!=null
&output.outputFile.name.endsWith('.apk'){
// Change the .apk name replacement newName as needed
defaultversionName = defaultConfig.versionName
def newName="vs_v${versionName}.apk"
output.outputFile=newFile(output.outputFile.parent, newName)
}
}
}
}
}
dependencies {
compilefileTree (dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile'com.android.support:appcompat-v7:23.3.0'
compile'com.google.android.gms:play-services-ads:7.5.0'
compile'com.google.code.gson:gson:2.4'
}
Thank you for your cooperation.
android
I don't know the exact cause, but I think I can improve some things.
We may not be able to resolve the issue, but for your information.
1.
You seem to be experiencing heavy activity every 0.175 seconds. You should avoid calling findViewById
and generating instances of the kyara_anim and kyara_i_jikkou classes.
The next program is an image, but how about putting ImageView
and kyara_anim and kyara_i_jikkou in instance variables that you found earlier in findViewById
and referring to them in anim?
private Runnable kyara_i_jikkou_runnable;
private Runnable kyara_anim_runnable;
private ImageView map_b1;
private ImageView map_b2;
private ImageView map_b3;
private ImageView map_b4;
// Run every 0.175 seconds*************************************
TimerTaskanim=new TimerTask(){
public void run() {
if(App.power==0&power_0==true){
power_0=false;
} else{
power_0 = true; // Once power is lost, it will be processed twice
if(kyara_i_t!=0){
// Go to run animation or running -------------------------
hdl.post(kyara_i_jikkou_runnable); // Go Run
} else if(map_b1.isPressed()||map_b2.isPressed()||map_b3.isPressed()||map_b4.isPressed()){
// If the key is pressed for a long time without moving -----------------------------
if(input==1){
kyara_i_t=1;
if(map_b1.isPressed())kyara_i=1;
if(map_b2.isPressed())kyara_i=2;
if(map_b3.isPressed())kyara_i=3;
if(map_b4.isPressed())kyara_i=4;
hdl.post(kyara_i_jikkou); // Go Run
}
} else{
// If nothing has been done, step-by-step ---------------------
hdl.post(kyara_anim_runnable);//Step Run
}
}
}
};
// The method name is appropriate, but consider it as an initialization process.
void init() {
...
map_b1=(ImageView) findViewById(R.id.map_b1);
map_b2=(ImageView) findViewById (R.id.map_b2);
map_b3=(ImageView) findViewById(R.id.map_b3);
map_b4=(ImageView) findViewById (R.id.map_b4);
kyara_i_jikkou_runnable=new kyara_i_jikkou();
kyara_anim_runnable=new kyara_anim();
...
}
2.
The img_img
method frequently switches images, so it looks like it can be improved as follows:
LevelListDrawable
https://developer.android.com/reference/android/graphics/drawable/LevelListDrawable.html
http://y-anz-m.blogspot.jp/2010/11/androidlevellistdrawable.html
3.
Android Studio comes with a CPU monitor and a GPU monitor.
If you look at it, I think it will be a clue to the cause of the slow animation.
https://developer.android.com/studio/profile/am-gpu.html
https://developer.android.com/studio/profile/am-cpu.html
© 2024 OneMinuteCode. All rights reserved.