有人可以帮助我吗?我正在制作一个简单的 Android 应用程序,它具有启动画面和带有按钮的主菜单,这应该会导致另一个“页面”并且可能会播放声音。该应用程序启动一秒钟,出现启动画面,然后应用程序崩溃。我还注意到按钮加载另一个页面需要一段时间:
我认为这条线与它有关:
12-05 23:36:57.710: I/ActivityManager(287): Displayed com.example.prva/.button: +1s167ms
这些是不断出现的红色错误:
12-07 14:24:28.301: E/ActivityThread(587): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d0c8d8 that was originally bound here
12-07 14:24:28.301: E/ActivityThread(587): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d0c8d8 that was originally bound here
12-07 14:24:28.301: E/ActivityThread(587): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
12-07 14:24:28.301: E/ActivityThread(587): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
12-07 14:24:28.301: E/ActivityThread(587): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
12-07 14:24:28.301: E/ActivityThread(587): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
12-07 14:24:28.301: E/ActivityThread(587): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
12-07 14:24:28.301: E/ActivityThread(587): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
12-07 14:24:28.301: E/ActivityThread(587): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
12-07 14:24:28.301: E/ActivityThread(587): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
12-07 14:24:28.301: E/ActivityThread(587): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
12-07 14:24:28.301: E/ActivityThread(587): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
12-07 14:24:28.301: E/ActivityThread(587): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
12-07 14:24:28.301: E/ActivityThread(587): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
12-07 14:24:28.301: E/ActivityThread(587): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-07 14:24:28.301: E/ActivityThread(587): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-07 14:24:28.301: E/ActivityThread(587): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-07 14:24:28.301: E/ActivityThread(587): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-07 14:24:28.301: E/ActivityThread(587): at java.lang.Thread.run(Thread.java:856)
12-07 14:24:28.312: E/StrictMode(587): null
12-07 14:24:28.312: E/StrictMode(587): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d0c8d8 that was originally bound here
12-07 14:24:28.312: E/StrictMode(587): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
12-07 14:24:28.312: E/StrictMode(587): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
12-07 14:24:28.312: E/StrictMode(587): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
12-07 14:24:28.312: E/StrictMode(587): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
12-07 14:24:28.312: E/StrictMode(587): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
12-07 14:24:28.312: E/StrictMode(587): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
12-07 14:24:28.312: E/StrictMode(587): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
12-07 14:24:28.312: E/StrictMode(587): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
12-07 14:24:28.312: E/StrictMode(587): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
12-07 14:24:28.312: E/StrictMode(587): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
12-07 14:24:28.312: E/StrictMode(587): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
12-07 14:24:28.312: E/StrictMode(587): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
12-07 14:24:28.312: E/StrictMode(587): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-07 14:24:28.312: E/StrictMode(587): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-07 14:24:28.312: E/StrictMode(587): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-07 14:24:28.312: E/StrictMode(587): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-07 14:24:28.312: E/StrictMode(587): at java.lang.Thread.run(Thread.java:856)
12-07 14:24:28.312: W/ActivityManager(273): Unbind failed: could not find connection for android.os.BinderProxy@40f409d8
12-07 14:24:28.322: E/ActivityThread(587): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d5ed58 that was originally bound here
12-07 14:24:28.322: E/ActivityThread(587): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d5ed58 that was originally bound here
12-07 14:24:28.322: E/ActivityThread(587): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
12-07 14:24:28.322: E/ActivityThread(587): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
12-07 14:24:28.322: E/ActivityThread(587): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
12-07 14:24:28.322: E/ActivityThread(587): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
12-07 14:24:28.322: E/ActivityThread(587): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
12-07 14:24:28.322: E/ActivityThread(587): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
12-07 14:24:28.322: E/ActivityThread(587): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
12-07 14:24:28.322: E/ActivityThread(587): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
12-07 14:24:28.322: E/ActivityThread(587): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
12-07 14:24:28.322: E/ActivityThread(587): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
12-07 14:24:28.322: E/ActivityThread(587): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
12-07 14:24:28.322: E/ActivityThread(587): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-07 14:24:28.322: E/ActivityThread(587): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-07 14:24:28.322: E/ActivityThread(587): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-07 14:24:28.322: E/ActivityThread(587): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-07 14:24:28.322: E/ActivityThread(587): at java.lang.Thread.run(Thread.java:856)
12-07 14:24:28.341: E/StrictMode(587): null
12-07 14:24:28.341: E/StrictMode(587): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d5ed58 that was originally bound here
12-07 14:24:28.341: E/StrictMode(587): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
12-07 14:24:28.341: E/StrictMode(587): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
12-07 14:24:28.341: E/StrictMode(587): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
12-07 14:24:28.341: E/StrictMode(587): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
12-07 14:24:28.341: E/StrictMode(587): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
12-07 14:24:28.341: E/StrictMode(587): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
12-07 14:24:28.341: E/StrictMode(587): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
12-07 14:24:28.341: E/StrictMode(587): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
12-07 14:24:28.341: E/StrictMode(587): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
12-07 14:24:28.341: E/StrictMode(587): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
12-07 14:24:28.341: E/StrictMode(587): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
12-07 14:24:28.341: E/StrictMode(587): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-07 14:24:28.341: E/StrictMode(587): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-07 14:24:28.341: E/StrictMode(587): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-07 14:24:28.341: E/StrictMode(587): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-07 14:24:28.341: E/StrictMode(587): at java.lang.Thread.run(Thread.java:856)
如果需要,我可以发布更多信息,提前谢谢!
我的 MainActivity.java :
package com.example.prva;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
public class MainActivity extends Activity {
MediaPlayer MPlayer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
MPlayer = MediaPlayer.create(this, R.raw.splash);
MPlayer.start();
Thread tajmer = new Thread(){
public void run(){
try{
int tajmer = 0;
while(tajmer == 0)
{
sleep(3500);
tajmer = tajmer +1;
}
startActivity(new Intent(MainActivity.this, Meni_Splash.class));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
tajmer.start();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
MPlayer.release();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
MPlayer.pause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
MPlayer.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
这是一个 Meni_Splash.java 代码:
package com.example.prva;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Meni_Splash extends Activity{
MediaPlayer ButtonClick;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Button click sound
final MediaPlayer ButtonClick = MediaPlayer.create(this, R.raw.button1);
Button btnv = (Button) findViewById(R.id.buttonv);
btnv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.prva.BUTTONVELIKI"));
ButtonClick.start();
}
});
Button btn3 = (Button) findViewById(R.id.buttonplay);
btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.prva.BUTTONPLAY"));
ButtonClick.start();
}
});
}
}
我的清单(我想我把这里和其他地方的一切都搞砸了......):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prva"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.prva.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Meni_Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
活动主.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/simplyfit">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="@string/pozdrav" />
<Button
android:id="@+id/buttonv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_alignParentBottom="true"
android:background="@drawable/button_v"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="2"
android:text="@string/buttonv"
android:textColor="#FFFFFF"
android:textSize="25sp"
android:textStyle="bold"
/>
</RelativeLayout>
按钮.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/splash">
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/text2"
android:text="@string/strana2"
android:textSize="30sp"
android:textStyle="bold|italic" />
<Button
android:id="@+id/buttonplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="225dp"
android:text="@string/textbuttonplay"/>
</LinearLayout>
按钮.java:
package com.example.prva;
import android.app.Activity;
import android.os.Bundle;
public class button extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.button);
}
}