Android pre`loading Activity - android

I have a question regarding the loading of the first Activity in my App. Before loading it, app shows this screen: https://www.dropbox.com/s/r33n3u3xfmth345/Screenshot_2013-08-16-12-02-08.png , and what I would like, is to load directly my Activity.
I'll mention that Im using SherlockActivity, and I already tried setting the Theme both in Manifest or programatically in onCreate() of my Activity, with same result (pre-loads with that screen for 2-3 secs, then loads my Activity).
Any thoughts ?

You have to use the splash screen Activity and after that you have to start your own activity from that Splash screen Activity.
Here is the code for splashActivity.
public class SplashActivity extends Activity {
private int splashTime = 3000;
private Thread thread;
private ProgressBar mSpinner;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
mSpinner = (ProgressBar) findViewById(R.id.Splash_ProgressBar);
mSpinner.setIndeterminate(true);
thread = new Thread(runable);
thread.start();
}
public Runnable runable = new Runnable() {
public void run() {
try {
Thread.sleep(splashTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
startActivity(new Intent(SplashActivity.this,YourActivityName.class));
finish();
} catch (Exception e) {
// TODO: handle exception
}
}
};
}
Here is code for activity_spalsh.xml file .....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#48AD83"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text=" your app name "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#A52A2A" />
<ProgressBar
android:id="#+id/Splash_ProgressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerInParent="true"
android:layout_marginTop="5dp" />
</RelativeLayout>

Related

Basic android app showing blank white screen?

I'm new to android studio. Right now I'm making a basic app that recursively counts down from 4 to 0 when you click a button on the screen. When I look at my activity_main.xml in Design view, it shows what I want, but when I run my app on my Virtual Device, it just shows a white screen with nothing on it. How can I fix this? I'll paste my code here, almost all of my code is in the activity_main.xml and MainActivity.java
Here is activity_main.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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >``
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/button1Contents"
android:onClick="sendMessage"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_toRightOf="#+id/button1"
android:text="#string/textView1Contents" />
</RelativeLayout>
and here is my MainActivity.java
public class MainActivity extends Activity {
private static final String TAG = "OneButtonRecursion";
public void sendMessage(View view) {
Button clickedButton = (Button) view;
if (clickedButton == findViewById(R.id.button1)) {
TextView cup = (TextView) findViewById(R.id.textView1);
int handFull = Integer.parseInt(cup.getText().toString());
if (handFull > 0) {
cup.setText(handFull + "");
playNextCup(cup, handFull);
}
} else {
}
}
public static void playNextCup(TextView cupIn, int handFullIn) {
handFullIn--;
cupIn.setText(handFullIn + "");
if (handFullIn != 0) {
playNextCup(cupIn, handFullIn);
Log.i(TAG, "In recursion " + handFullIn);
} else {
}
}
}
and here is my strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">One Button Recursion</string>
<string name="action_settings">Settings</string>
<string name="button1Contents">Button1</string>
<string name="textView1Contents">4</string>
</resources>
You just forgot to Override onCreate() method
onCreate() Called when the activity is starting. This is where most initialization should go: calling setContentView(int) to inflate the activity's UI,
Just Override onCreate() inside your activity it will
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

start Activity B(called by onCreate of an Application Class's sub Class) on Top of Activity A(called by onResume of an Activity Class's sub Class)

I have 2 activities that involved in this question:
LoginActivity: A Login in Screen (called by a subclass of Activity Class)
Updater Activity: A Update Screen that show updating progress when new app version is availble (called by a subclass of Application Class)
This is what I want:
When the app FIRST LAUNCH, and if new version of the app is available, the UPDATER ACTIVITY should be on top of every activity include the Login Activity,
so it will be the first screen user see during first launch of the app.
only after the updating progress is done, the UPDATER ACTIVITY will be dismissed then Login Screen be on top.
However this is what actually happened:
The LOGIN ACTIVITY always on top of UPDATER ACTIVITY...
My Guess is that since the UPDATER ACTIVITY is called By APPLICATION CLASS's subClass, and the LOGINACTIVITY is called by an ACTIVITY CLASS sub class,
the Application class's method such as OnResume always get called before Activity onCreate Method, thus the LOGINACTIVITY always appear on top of UPDATER ACTIVITY,
I just wondering if there is anyway I could make my UPDATER ACTIVITY be on top of any activities including the LOGIN ACTIVITY?
//LoginActivity involved
public abstract ClassA extends Activity {
.....
.....
protected void onResume() {
super.onResume();
.....
if(isAuthenticated){
Intent intent = new Intent(this, LoginActivity.class)
.putExtra(...)
startActivityForResult(intent, XXX);
}
}
}
====
//Updater Activity involved
public abstract class ClassB extends Application {
....
....
....
public void onCreate() {
super.onCreate();
Intent updaterIntent = new Intent(this, UpdaterActivity.class);
updaterIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(updaterIntent);
}
}
i have diffrent solution instent of activity create dialog box activity.
public class ViewDialog {
public void showDialog(Activity activity, String msg){
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setContentView(R.layout.updatedialog);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
Button dialogUpdate = (Button) dialog.findViewById(R.id.update);
Button dialogcancel = (Button) dialog.findViewById(R.id.cancel);
Button dialogremindme = (Button) dialog.findViewById(R.id.remindeme);
TextView textView= (TextView) dialog.findViewById(R.id.machhint1);
TextView textView2= (TextView) dialog.findViewById(R.id.machhint2);
textView2.setText("Your old version is : "+versionName);
textView.setText("Current version in playstore : "+version);
dialogcancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialogUpdate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
SharedPreferences.Editor editoradddetail1 = getSharedPreferences("later", MODE_PRIVATE).edit();
editoradddetail1.putString("days", "");
editoradddetail1.commit();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
later="";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
dialog.dismiss();
}
});
dialogremindme.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences.Editor editoradddetail1 = getSharedPreferences("later", MODE_PRIVATE).edit();
Date someDate = new Date(); // Or whatever
Date dayAfter = new Date(someDate.getTime() + TimeUnit.DAYS.toMillis( 2 ));
DateFormat dateFormat=new SimpleDateFormat("dd/MM/yyyy");
String formattedDate=dateFormat.format(dayAfter);
editoradddetail1.putString("days", formattedDate);
editoradddetail1.commit();
dialog.dismiss();
}
});
dialog.show();
}
}
//and xml is.
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="250dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="250dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/main"
android:background="#FFed6904"
android:layout_height="120dp">
<TextView
android:id="#+id/machhint"
android:text="Note:- Your current Version Did Not Match"
android:layout_width="match_parent"
android:textColor="#color/white"
android:textSize="13dp"
android:layout_height="60dp" />
<TextView
android:id="#+id/machhint1"
android:text="preschool version is"
android:layout_width="wrap_content"
android:textSize="13dp"
android:textColor="#color/white"
android:layout_below="#+id/machhint"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/machhint2"
android:text="Your Vertion is :"
android:layout_width="wrap_content"
android:textColor="#color/white"
android:textSize="13dp"
android:layout_below="#+id/machhint1"
android:layout_height="30dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/text1"
android:layout_below="#+id/main"
android:layout_height="40dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEXTO"
android:id="#+id/text_dialog"
android:layout_marginTop="3dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="3dp"
android:textSize="18sp"
android:textColor="#ff000000"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_below="#+id/text1"
android:gravity="center_vertical|center_horizontal"
android:layout_height="55dp">
<Button
android:layout_width="wrap_content"
android:layout_height="45dp"
android:text="Update"
android:id="#+id/update"
android:gravity="center"
android:layout_toLeftOf="#+id/remindeme"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="45dp"
android:text="Later"
android:id="#+id/remindeme"
android:gravity="center"
android:layout_centerHorizontal="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="45dp"
android:text="Cancel"
android:id="#+id/cancel"
android:gravity="center"
android:layout_toRightOf="#+id/remindeme"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>

android - Load progress bar layout before loading main layout

I have a dummy RelativelayoutView with progress bar.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/progressbar">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="#+id/progressBar" />
</RelativeLayout>
When my app starts I need this RelativelayoutView to appear for 5 seconds and should diappear with or without animation.
I'm not sure I understood your question, but I'd suggest you to write something like this in your activity:
private Handler mHandler;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
mHandler = new Handler(Looper.getMainLooper());
mHandler.postDelayed(new Runnable() {
public void run() {
// hide your progress bar
findViewById(R.id.progressBar).setVisibility(View.GONE);
// or finish this activity and start a new one
startActivity(new Intent(MyActivity.this, MySecondActivity.class));
}
}, 5000);
}
#Override
public void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(null);
}
And I think you should add the android:indeterminate="true" attribute to your progress bar.
Hope it helps. Cheers.

Gesture Overlay on SplashScreen

I'm trying to use a gesture overlay on a activity that is used as a splash screen.
The problem is when I : gOverlay = (GestureOverlayView) this.findViewById(R.id.gOverlay); , gOverlay is null.
This is my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center" android:background="#000000"
android:weightSum="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.11">
<android.gesture.GestureOverlayView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/gOverlay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:visibility="visible"
android:background="#000000"
>
</android.gesture.GestureOverlayView>
</RelativeLayout>
</LinearLayout>
This is Splash java code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
/** set time to splash out */
Bundle extras = getIntent().getExtras();
if (extras != null) {
Duration = extras.getString("Duration");
}
welcomeScreenDisplay = 4000;
try {
welcomeScreenDisplay = Integer.parseInt(Duration);
} catch (Exception x) {
}
gLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!gLibrary.load()) {
finish();
}
gOverlay = (GestureOverlayView) this.findViewById(R.id.gOverlay);
gOverlay.setGestureVisible(false);
gOverlay.addOnGesturePerformedListener(this);
/** create a thread to show splash up to splash time */
Thread welcomeThread = new Thread() {
int wait = 0;
#Override
public void run() {
try {
super.run();
while (wait < welcomeScreenDisplay) {
sleep(100);
wait += 100;
}
} catch (Exception e) {
System.out.println("EXc=" + e);
} finally {
finish();
}
}
};
welcomeThread.start();
}
What i'm trying to do is :
1. When user presses back button Splash screen will show.
2. This splash screen will be on the screen for n seconds
3. If the user draw a 'L' on the splash screen, implicit on Gesture Overlay, main activity will .finish()
Thanks
From the comments you gave, it seems that you are inflating the wrong layout.
You said, the layout containing the GestureOverlayView is named splash2.
setContentView(R.layout.splash);
But instead you are inflating splash, not splash2. If splash.xml does not contain the GestureOverlayView with android:id="#+id/gOverlay", then requesting gOverlay from splash, will throw a nullpointer.
Changing setContentView() in your activity to following should help:
setContentView(R.layout.splash2);

App loading splash screen with processbar and Text for showing percentage of loading

I am working on splash screen for my android app. The screen starts from my MainActivity.java, in which onCreate() method contains the following code. Also the same activity class is loading maps in its onResume() method and in it i m loading a new layout which is activity_main.xml. That xml has black screen and no background screen.
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.loading_screen);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
textView = (TextView) findViewById(R.id.textView1);
new Thread(new Runnable() {
public void run() {
while (progressStatus < 100) {
progressStatus += 1;
handler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus + "/"
+ progressBar.getMax());
}
});
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
compass = new CompassSensor(this, compassHandler);
}
my layout for loading_screen.xml is as follow.
loading_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/splash_screen_loading" xmlns:android="http://schemas.android.com/apk/res/android">
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/progressBar1"
android:layout_marginLeft="15dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
The problem i m facing is that only black screen shows during app loading. I tried to debug the problem but all my efforts were useless. Plz help.
You should not attempt this in onCreate, if you expect visual changes. Nothing is shown to user during onCreate. I am aware of Thread.sleep(200).
You may want to try doing it in your onResume, just after calling super.onResume. The way you described it, R.layout.loading_screen is not even supposed to be shown.
Also, if you're using AsyncTask to load maps, Developers lets you know how to publish progress. Take a look at this: AsyncTask. Maybe you could add this prior work (with progress on R.layout.loading_screen) to asynchronous task, too.

Categories

Resources