30/09/2018, 16:21
Lỗi : UnsupportedOperationException?
Em có làm cái thread Splash Screen mà chạy ứng dụng nó đóng ngay tại chỗ . Đây là LogCat của em :
12-30 21:15:58.493 1559-1593/com.example.zaloao E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-158
java.lang.UnsupportedOperationException
at java.lang.Thread.stop(Thread.java:1076)
at java.lang.Thread.stop(Thread.java:1063)
at com.example.zaloao.MainActivity$1.run(MainActivity.java:38)
12-30 21:15:58.549 1559-1559/com.example.zaloao W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
12-30 21:15:59.105 1559-1559/com.example.zaloao D/OpenGLRenderer﹕ TextureCache::flush: target size: 445327
12-30 21:15:59.105 1559-1559/com.example.zaloao D/OpenGLRenderer﹕ TextureCache::callback: name, removed size, mSize = 1, 739908, 2304
Đây là phần Java code:
package com.example.zaloao;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
public class MainActivity extends ActionBarActivity {
protected boolean _active = true;
protected int _splashTime = 5000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
finish();
Intent mainIntent = new Intent(MainActivity.this, Welcome.class);
MainActivity.this.startActivity(mainIntent);
MainActivity.this.finish();
stop();
}
}
};
splashTread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
_active = false;
}
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, 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);
}
}
Đây là phần code xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/img_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/main_welcome"
/>
</LinearLayout>
Ai đi qua xem dùm em với nha .
Bài liên quan
gọi
stop()
trongThread
làm gì thế?mà code loằng ngoằng linh tinh quá, đơn giản thôi.
trời. Code có xíu mà e làm dài gấp 5 lần a