gpt4 book ai didi

Android 创建一个没有按钮的 Activity

转载 作者:行者123 更新时间:2023-11-29 21:07:46 25 4
gpt4 key购买 nike

我很困惑为什么我不能让它工作。当我在后台做一些事情时,我想让一个没有按钮的屏幕运行 5 秒钟,然后导航回另一个屏幕。这不可能吗?

我曾尝试将运行后台项的代码放在 onCreate、onStart 和 onResume 中,所有这些方法都在屏幕实际显示之前触发。还有其他方法吗?

编辑我的代码的最新版本:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sync);

}

protected void onResume(){
super.onResume();
commitSync();
}

private void commitSync(){

TextView monthDayYear = (TextView)findViewById(R.id.month_day_year);
TextView hourMinuteSecond = (TextView)findViewById(R.id.hour_minute_second);

_application = (App)getApplicationContext();

try {
CountDownLatch latch = new CountDownLatch(1);
latch.await(5, TimeUnit.SECONDS);
//Ensure that we have flash
if(getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
Camera androidCamera = Camera.open();
Camera.Parameters p = androidCamera.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
androidCamera.setParameters(p);
//Flash and then turn off
androidCamera.startPreview();
latch.await(50, TimeUnit.MILLISECONDS);
androidCamera.stopPreview();
//Flash screen white
//Get date and time
Module syncModule = _application.getModule();
syncModule.start();
Calendar syncTime = syncModule.getDateAndTime();
//http://stackoverflow.com/questions/21988004/get-time-in-hhmmss-from-seconds-in-java
monthDayYear.setText(new SimpleDateFormat("MM/dd/yyyy").format(syncTime.getTime()));
hourMinuteSecond.setText(new SimpleDateFormat("HH:mm:ss:00").format(syncTime.getTime()));

//Navigate back to MainActivity
Intent mainActivityIntent = new Intent(SyncActivity.this, MainActivity.class);
startActivityForResult(mainActivityIntent, 1);
} else {
throw new Exception("Cannot access Android Flash");
}


} catch (Exception ex) {
Util.appendLog("Exception occured in Sync: " + ex.getMessage());
}
}

最佳答案

也许这对你有帮助:

Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run() {
// Do some work like:

finish();
}
}, 500);

这会在延迟一段时间后运行一段代码,您可以将这段代码放在您想要的屏幕上。

关于Android 创建一个没有按钮的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23964071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com