[英]Android activity starting twice on startup
public class SplashActivity extends Activity {
private static String TAG = SplashActivity.class.getName();
private static long SLEEP_TIME = 4; // Time to display the splash image for
// in seconds.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes
setContentView(R.layout.activity_splash);
Log.d("man", "Starting app");
testHttp test = new testHttp();
test.test();
}
Here is the Manifest 这是清单
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.rhino68mobileapp.SplashActivity"
android:label="@string/title_activity_splash" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When I run my app on my device this is what the logs read: 当我在设备上运行应用程序时,日志显示如下:
03-06 06:12:16.819: D/man(2105): Starting app
03-06 06:12:16.819: D/TEST(2105): Starting test
03-06 06:12:16.869: D/TEST(2105): make request
03-06 06:12:16.869: D/man(2105): Starting app
03-06 06:12:16.869: D/TEST(2105): Starting test
03-06 06:12:16.869: D/TEST(2105): make request
Try this for your splash screen: 为您的启动屏幕尝试以下操作:
public class Splash extends Activity implements Runnable {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Handler handler = new Handler();
handler.postDelayed(this, 1500); // SLEEP_TIME in milis
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.splash, menu);
return true;
}
public void run(){
startActivity(new Intent(this, Main.class)); // Call the after splash screen
finish();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.