gpt4 book ai didi

android - Android 中带有 2 个图像的启动画面

转载 作者:太空狗 更新时间:2023-10-29 14:09:30 30 4
gpt4 key购买 nike

我在我的 Android 应用程序中设置了启动画面,它运行网络调用的长度,然后切换到主要( map ) Activity 。

我想知道我是否可以在此启动画面中使用第二张图片作为列出赞助商的方式。我现在的飞溅持续长达 5 或 6 秒,所以我不想添加第二次飞溅 Activity 。

我希望我可以向当前 Activity 添加第二张图片。第一个持续 2 秒,第二个持续网络通话的剩余时间。

这是我的部分代码。请让我知道是否可以将其添加到现有代码中。谢谢!

   



// Splash screen timer
private static int SPLASH_TIME_OUT = 1000;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
ConnectivityManager conectivtyManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (conectivtyManager.getActiveNetworkInfo() != null
&& conectivtyManager.getActiveNetworkInfo().isAvailable()
&& conectivtyManager.getActiveNetworkInfo().isConnected()) {
isConnected = true;
} else {
isConnected= false;
}

if(isConnected)
new LoadAllVendors().execute();
else
{
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent1 = new Intent(SplashScreen.this, ShoppingListActivity.class);
finish();
startActivity(intent1);
}
}, 5000);
}

}

class LoadAllVendors extends AsyncTask<String, String, String> {

/**
* getting All vendors from url
*/
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_vendors, "GET", params);
JSONObject json1 = jParser.makeHttpRequest(url_all_products, "GET", params);
JSONObject json2 = jParser.makeHttpRequest(url_all_vps, "GET", params);

dataSource = new VendorsDataSource(getApplicationContext());
dataSource1 = new ProductsDataSource(getApplicationContext());
dataSource2 = new VandPDataSource(getApplicationContext());

dataSource.open();
dataSource1.open();
dataSource2.open();



// Check your log cat for JSON reponse
//Log.d("All Products: ", json.toString());

try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
int success1 = json1.getInt(TAG_SUCCESS);
int success2 = json2.getInt(TAG_SUCCESS);

if (success == 1) {
// products found
// Getting Array of Products
vendors = json.getJSONArray(TAG_VENDORLOCNS);
vendorIDs = new ArrayList<>();

// looping through All Products
List<Vendor> allVendors = new ArrayList<>();
for (int i = 0; i < vendors.length(); i++) {
JSONObject c = vendors.getJSONObject(i);

Vendor vendor = new Vendor(c.getInt(TAG_VENDORID), c.getString(TAG_NAME), c.getDouble(TAG_VENDORLOCNLONG), c.getDouble(TAG_VENDORLOCNLAT), c.getInt(TAG_VENDORHEARTS), c.getInt(TAG_VENDORTODOS)
, c.getString(TAG_VENDOROWNER), c.getString(TAG_VENDOREMAIL), c.getString(TAG_VENDORPHONE), c.getString(TAG_ABOUT), c.getString(TAG_WEBSITE), c.getString(TAG_VENDORIMAGE));
allVendors.add(vendor);
MarkedVendor v = new MarkedVendor(c.getInt(TAG_VENDORID), c.getString(TAG_NAME), false, false);
vendorIDs.add(vendor.getId());
dataSource.createVendor(vendor);
dataSource.createSavedVendor(v);
}
dataSource.deleteVendorTable(vendorIDs);
dataSource.close();
}

if (success1 == 1) {
// products found
// Getting Array of Products
products = json1.getJSONArray(TAG_PRODUCTS);

// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);

Product product = new Product(c.getInt(TAG_PRODUCTID), c.getString(TAG_PRODUCTNAME), c.getString(TAG_DISTINGUISHER));
dataSource1.createProduct(product);
}

dataSource1.close();
}

if (success2 == 1) {
// products found
// Getting Array of Products
vandps = json2.getJSONArray(TAG_VPS);
vpIDs = new ArrayList<>();
// looping through All Products
List<VandP> allVandPs = new ArrayList<>();
for (int i = 0; i < vandps.length(); i++) {
JSONObject c = vandps.getJSONObject(i);

VandP vandp = new VandP(c.getInt(TAG_VPID), c.getInt(TAG_VP_VENDORID), c.getInt(TAG_VP_PRODUCTID));
dataSource2.createVandP(vandp);
allVandPs.add(vandp);
vpIDs.add(vandp.getVpID());
}
dataSource2.deleteVandPTable(vpIDs);
dataSource2.close();

}

} catch (JSONException e) {
e.printStackTrace();
}

return null;
}

protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
Intent intent = new Intent(SplashScreen.this, MapsActivity.class);
Intent helpIntent = new Intent(SplashScreen.this, HelpActivity.class);

boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUNMapsActivity", true);
if(!isFirstRun) {
startActivity(intent);
finish();
}
else {
startActivity(helpIntent);
finish();
}
}
});

}
}

}

最佳答案

我只想在这里添加另一个处理程序

Handler mHandler;
...

if(isConnected){
new LoadAllVendors().execute();
mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
//set the second image
}
}, 2000);
}

protected void onDestroy(){
...
// make sure to clean up handlers when activity is destroyed
if (mHandler != null)
mHandler.removeCallbacksAndMessages(null);
}

此外,您不需要在 onPostExecute block 中执行 runOnUiThread。它已经在 UI 线程上运行,因此您应该将其删除。

关于android - Android 中带有 2 个图像的启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30115053/

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