Dismiss splash activity on resume - android

I have two activities in my application. SplashActivity and MainActivity. Here is their manifest definition.
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I want to finish SplashActivity after it shown , as you see it is defined as noHistor and calling MainActivity after 10 seconds so ;
Intent a = new Intent(this,MainActivity.class);
a.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);
finish();
When i take application to background and trying to resume , it is not resuming from MainActivity , it shows SplashActivity again.. how can i prevent this ? is it a known bug ?
Thank you very much

Related

return back to previous screen with back button

when my app starts it says to Login if you don't login you can register
in the register screen if you press back btn you don't turn back to login but the app is closing. any ideas?
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/Theme.Design.Light.NoActionBar">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegisterActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Setting"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".History"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Fall_test"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Examples"
android:screenOrientation="portrait">
</activity>
</application>
When you start register activity like
Intent mIntent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(mIntent);
this.finish(); OR LoginActivity.this.finish();
Just remove the below one if you used it
this.finish(); OR LoginActivity.this.finish();
and just start RegisterActivity like this
Intent mIntent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(mIntent);
When you press back button inside RegisterActivity it will get you back to LoginActivity.
You are finishing / destroying your activity when you're moving to another activity. When you go from one actity to another, the old activity is reserved in a stack. And when you press back button, it's popped back from the stack. So, if you finish the old one while moving to the new one, the activity won't be reserved in the stack, thus you are being forced to exit the app as there's no activity on the stack.

Back button calls onDestroy() on parent

Why does the back tubbon call onDestroy() on the parent?
I have the following scenario:
Activity A that opens Activity B via an intent
Intent intent = new Intent(parent.getContext(), activityB.class);
intent.putExtra(STATE_REST, gson.toJson(myObject));
startActivity(intent);
When I click on back on activity B (and only then) activity A fires onDestroy() followed by onCreate().
Manifest:
Activity A
<activity
android:name=".activities.MainActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Activity B
<activity
android:name=".activities.MenuActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:label="#string/menu_title"
android:parentActivityName=".activities.MainActivity">
</activity>
your problem seems to be resolved in the flowing link:
Why is onDestroy always called when returning to parent activity?
Good luck.

Reload Just the Main Activity not the Launcher Activity

I'm using this code to refresh MainActivity.java when a Refresh button is pressed.
Intent intent = getIntent();
finish();
startActivity(intent);
MainActivity.java has the category default and there is another Launcher activity. So whenever I press the Refresh button the Launcher Activity also starts again. I only need to start the MainActivity class. Below is the manifest
<application
android:allowBackup="true"
android:icon="#drawable/play_icon"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
<activity
android:name="com.theanilpaudel.joshilo.FirstScreen"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.theanilpaudel.joshilo.MainActivity"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
What you are looking for in this case is an explicit Intent that launches MainActivity.
You can do this like so:
Intent mainIntent = new Intent(this, MainActivity.class);
startActivity(mainIntent);
This will ensure that the Intent only launches MainActivity.
However, I highly recommend re-evaluating why you need to completely restart the Activity to refresh it. There are much cheaper (faster and less resource intensive) methods of updating data displayed in an Activity.
I guess I know the culprit. Try using the following code once.
Intent intent = getIntent();
startActivity(intent);
finish();
As far as I know startActivity() uses context to run. In case if you call finish() before startActivity() that may lead to destroy context of MainActivity and will get the application's context i.e. fires the activity with behavior LAUNCHER or MAIN.
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Let me know if it helps or you still have difficulty reloading activity.
Cheers

Starting music player intent closes the parent activity

Activity A start muzic player(B) with intent, going back from music player shows the homescreen not activty A.
here is the acitvity in manifest
<activity android:name="myactivity"
android:launchMode="singleTop"
android:noHistory="true"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and Intent to start muzic player
Intent i = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/"+"rec1.wav");
i.setDataAndType(uri, "audio/*");
startActivity(i);
Expected results: Going back from muzicplayer, activity A shall be visible as per activity life cycle.
Hi the problem is your android:noHistory="true"
please remove this from your XML.
<activity android:name="myactivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
hope this might be help you.

How do I get rid of this pointer in between Activities?

image of the offending pointer:
http://i842.photobucket.com/albums/zz347/oxygen_addict/bugs/device.png
the problem is that this pointer shows up whenever I transition from one activity to another.
code of the intent's:
final Intent intent = new Intent(ActivityTwo.this, test.app.com.ActivityOne.class);
startActivity(intent);
final Intent intent = new Intent(ActivityOne.this, test.app.com.ActivityTwo.class);
startActivity(intent);
Manifest:
<!-- LAUNCH ACTIVITY -->
<activity android:name=".ActivityOne"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- SUB-ACTIVITIES -->
<activity android:name=".ActivityTwo"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:noHistory="true"
android:theme="#android:style/Theme.NoTitleBar" />
Note:
within onCreate() of each activity I am using
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
How can I get rid of the pointer ?
FYI: the OS has to be rebuilt to remove the pointer.
Would have been awesome to have an Application-level API available to control it....

Categories

Resources