显示正在加载 activity 直到 main activity 完全加载
Showing Loading activity until main activity is fully loaded
这里是 activity 的主要代码,将在 onCreate 方法完全执行后加载。
引用 This for closing one activity from another
public class DictionarySscWords extends AppCompatActivity implements View.OnClickListener, TextToSpeech.OnInitListener
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
context = this;
Intent myIntent = new Intent(DictionarySscWords.this,LoadingIt.class);
startActivity(myIntent);
setContentView(R.layout.activity_main);
//all this activity work
LoadingIt.fa.finish(); //close Loading activity
}
}
下面是我的loadingIt的代码activity
public class LoadingIt extends AppCompatActivity {
Context context;
public static LoadingIt fa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loading_it);
context=this;
fa = this;
ProgressDialog dialog=new ProgressDialog(context);
dialog.setMessage("Loading Please wait!!");
dialog.setCancelable(false);
dialog.setInverseBackgroundForced(false);
dialog.show();
}
}
问题是 LoadingIt activity 从未完成并且应用程序卡在加载屏幕上我想完成这个activity 作为之前的活动 onCreate方法完全执行
谢谢
我觉得您的解决方案并不是真正的最佳实践。这是我会做的:
声明LoadingIt
activity为启动项activity
在onCreate
方法中,加载后台需要的资源(比如AsyncTask
或者IntentService
)
加载完成后,完成LoadingIt
activity并显示DictionarySscWords
activity
如果你post加载逻辑,我可以提供一个示例实现。
你可以在LoadingIt的onCreate()中使用Threadclass
public class LoadingIt extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_loading_it);
Thread loadingThread = new Thread() {
@Override
public void run() {
try {
super.run();
sleep(2000);
} catch (Exception e) {
} finally {
Intent main = new Intent(LoadingIt.this,MainActivity.class);
startActivity(main);
finish();
}
}
};
loadingThread.start();
}
这里是 activity 的主要代码,将在 onCreate 方法完全执行后加载。
引用 This for closing one activity from another
public class DictionarySscWords extends AppCompatActivity implements View.OnClickListener, TextToSpeech.OnInitListener
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
context = this;
Intent myIntent = new Intent(DictionarySscWords.this,LoadingIt.class);
startActivity(myIntent);
setContentView(R.layout.activity_main);
//all this activity work
LoadingIt.fa.finish(); //close Loading activity
}
}
下面是我的loadingIt的代码activity
public class LoadingIt extends AppCompatActivity {
Context context;
public static LoadingIt fa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loading_it);
context=this;
fa = this;
ProgressDialog dialog=new ProgressDialog(context);
dialog.setMessage("Loading Please wait!!");
dialog.setCancelable(false);
dialog.setInverseBackgroundForced(false);
dialog.show();
}
}
问题是 LoadingIt activity 从未完成并且应用程序卡在加载屏幕上我想完成这个activity 作为之前的活动 onCreate方法完全执行
谢谢
我觉得您的解决方案并不是真正的最佳实践。这是我会做的:
声明
LoadingIt
activity为启动项activity在
onCreate
方法中,加载后台需要的资源(比如AsyncTask
或者IntentService
)加载完成后,完成
LoadingIt
activity并显示DictionarySscWords
activity
如果你post加载逻辑,我可以提供一个示例实现。
你可以在LoadingIt的onCreate()中使用Threadclass
public class LoadingIt extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_loading_it);
Thread loadingThread = new Thread() {
@Override
public void run() {
try {
super.run();
sleep(2000);
} catch (Exception e) {
} finally {
Intent main = new Intent(LoadingIt.this,MainActivity.class);
startActivity(main);
finish();
}
}
};
loadingThread.start();
}