Home button or home activity ? - Android Software Development

Hi to every one.
How can I check inside the OnRestart method, if the home button was released ?
or
When the home button is released then the following intent is called Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher/.Launcher }.
How to check inside the method onRestart that the above Intent was called ?
Thank you in advance.

Related

Restart Activity

Hello,
I have some kind of a special question...
I am new in Android programming and I wonder if it's posible to restart an application after the home-button stopped it. Since I know, the application is not destroyed, only stopped.
So, I thought doing something like this:
Code:
protected override void OnStop()
{
base.OnStop();
StartActivity(new Intent(this, typeof(MyActivity)));
}
Obviously that does not work. How can I "refocus" my Activity after the home-button closed it?
Thanks a lot!
Kuehner
Hello,
I have news. Restart works when I do this:
protected override void OnStop()
{
base.OnStop();
if (!guiHandler.TestStopped)
{
Intent intent = new Intent(this, this.Class);
StartActivity(intent);
}
//Finish();
}
My problem now:
I have to finish my old activity to start a new one. But I only want to restart a stopped activity without destroying it. Is this possible?
start the intent and finish the intent at the same time.
How do I do that?
Intent intent = new Intent(first.class, second.class);
startActivity(intent);
finish();
replace first.class and second.class with the classname.
Ok, thanks for your help. Now I understand.
The problem is that I do not want my activity to finish. When the user presses the home-button, the activity runs in background (for a couple of minutes) and there I want my activity to refocus again (without restarting, it's more "refocusing", so that the old state appears again).
I do not want my activity to finish!
i already tried it too.. but found nothing.. i solved my problem so.. :/

[Q] Change text in button after press

Hi, I need to change the text inside of a button after it has been pressed. How would I do this?
Thanks
//in your activity... get the button:
Button button = (Button) findViewById(R.id.myButton);
//make a click listener/handler:
OnClickListener myClickListener = new OnClickListener() {
...public void onClick(View v) {
......button.setText("New Text");
...}
};
//set the listener:
button.setOnClickListener(myClickListener);
I keep getting errors for the last line "button.setOnClickListener(myClickListener); "
Nevermind I got it... THANKS A MILLION!

[Q] update view of activity that implements onClickListener without needing to click

How do you update an activity that implements on click listener WITHOUT needing to click something? (e.g. with a timer)
What is it you are trying to do? Why the new thread?
I need to update button, background images and text based on a timer instead of only updating when something is clicked
I don't understand what you mean by "only updating when something is clicked."
the images used (e.g. back ground, or buttons) will not change (update) unless a button is clicked. So its basically waiting for something to be pressed (any button) before it updates any imgaes
So let me get this straight; you're changing the images associated with layout controls in a timer of some kind? What kind of timer implementation? Is the timer in its own thread?
yeah. I tried making another class for the time but it doesn't work for updating the view of the main activity that I want. So I am trying to use:
Timer timer2 = new Timer();
timer2.scheduleAtFixedRate(Title(), 1, 1000);
Title() is defined as: public TimerTask Title()
NEVERMIND!! I GOT IT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
TimerTask scanTask;
final Handler handler = new Handler();
Timer t = new Timer();
scanTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
// stuff to do
}
});
}};
t.schedule(scanTask, 1, 1000);

[Q] How to link to Settings>Account>Location?

I can link to System settings>Location access with Settings.ACTION_LOCATION_SOURCE_SETTINGS
Fine...but I want to link to System settings>Accounts(Google)>Location settings (this screen is called Google apps location settings)
Does someone know how to do this? Or at least how to get close to there?
Another issue I'm struggling with is how to link to PlayStore>Settings>Ads screen. Has someone an idea?
In the App Ops screen on Android 4.3, find the activity in the settings that you like to open, and launch it the usual way via intent. If you don't have 4.3 yet, you'd have to look at the Android source code and find it there
SimplicityApks said:
In the App Ops screen on Android 4.3, find the activity in the settings that you like to open, and launch it the usual way via intent. If you don't have 4.3 yet, you'd have to look at the Android source code and find it there
Click to expand...
Click to collapse
Thank you for your reply. I can try 4.3 soon. I planned to be compatible with 4.1+. If it is only possible to support 4.3+, that is at least something. Can you tell me how I can code it under 4.3+?`
I would list all activities on my device using the solution provided here.
Then choose the right one from the settings app.
alterechtschreibung said:
Thank you for your reply. I can try 4.3 soon. I planned to be compatible with 4.1+. If it is only possible to support 4.3+, that is at least something. Can you tell me how I can code it under 4.3+?`
Click to expand...
Click to collapse
OK sry, my fault. You don't need 4.3, just create a shortcut in Nova Launcher with activities - >settings and search the right activity. Why I thought 4.3 was needed is only because that was where I created a shortcut on the Homescreen to an activity the last time...
The code itself is clear:
Code:
Intent I = new Intent( "com.google.android.location.settings.GoogleLocationSettingsActivity" );
startActivity(i);
Edit got it!
You probably mean this screen:
"com.google.android.location.settings.GoogleLocationSettingsActivity"
SimplicityApks said:
OK sry, my fault. You don't need 4.3, just create a shortcut in Nova Launcher with activities - >settings and search the right activity. Why I thought 4.3 was needed is only because that was where I created a shortcut on the Homescreen to an activity the last time...
The code itself is clear:
Code:
Intent I = new Intent( "com.google.android.location.settings.GoogleLocationSettingsActivity" );
startActivity(i);
Edit got it!
You probably mean this screen:
"com.google.android.location.settings.GoogleLocationSettingsActivity"
Click to expand...
Click to collapse
Thank you. Unfortunately app crashes when calling it:
I/ActivityManager( 1473): START {act=com.google.android.location.settings.GoogleLocationSettingsActivity u=0} from pid 3501
D/AndroidRuntime( 3501): Shutting down VM
W/dalvikvm( 3501): threadid=1: thread exiting with uncaught exception (group=0x40a9f300)
E/AndroidRuntime( 3501): FATAL EXCEPTION: main
E/AndroidRuntime( 3501): java.lang.IllegalStateException: Could not execute method of the activity
alterechtschreibung said:
Thank you. Unfortunately app crashes when calling it:
I/ActivityManager( 1473): START {act=com.google.android.location.settings.GoogleLocationSettingsActivity u=0} from pid 3501
D/AndroidRuntime( 3501): Shutting down VM
W/dalvikvm( 3501): threadid=1: thread exiting with uncaught exception (group=0x40a9f300)
E/AndroidRuntime( 3501): FATAL EXCEPTION: main
E/AndroidRuntime( 3501): java.lang.IllegalStateException: Could not execute method of the activity
Click to expand...
Click to collapse
I also modified the code with no luck:
public void showClick_google_apps_location_settings(View view) {
Intent intent = showGoogleAppsLocationSettings();
startActivity(intent);
}
public static Intent showGoogleAppsLocationSettings() {
Intent intent = new Intent("com.google.android.location.settings.GoogleLocationSettingsActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
return intent;
}
Strange... Normally this should work... Maybe try to set the method not static but that shouldn't do anything actually.
SimplicityApks said:
Strange... Normally this should work... Maybe try to set the method not static but that shouldn't do anything actually.
Click to expand...
Click to collapse
Do I need certain permissions for com.google.android.location.settings.GoogleLocationSettingsActivity?
Usually not... You're testing on a real device, not an emulator aren't you?
SimplicityApks said:
Usually not... You're testing on a real device, not an emulator aren't you?
Click to expand...
Click to collapse
I'm on a real device with Android 4.1.x
I tried Nova Launcher. There is this entry:
settings.GoogleLocationSettings$Activity
Google apps location settings
This shortcut in Nova works. In my app it causes the crash.
If there is further code required, just tell me.
I hope probably not.That's it....
Sent from my Xperia U using xda app-developers app
Karchikumar said:
I hope probably not.That's it....
Sent from my Xperia U using xda app-developers app
Click to expand...
Click to collapse
What's wrong with testing on a real device? Finally the app must run on real devices and not in an emulator.
alterechtschreibung said:
What's wrong with testing on a real device? Finally the app must run on real devices and not in an emulator.
Click to expand...
Click to collapse
Nothing, testing on the emulator could crash since the Goggle settings may not be installed.
Really interesting and strange that it crashes, the only thing you can do now is to try other shortcuts and see if they work and it is just the Google location setting.
SimplicityApks said:
Nothing, testing on the emulator could crash since the Goggle settings may not be installed.
Really interesting and strange that it crashes, the only thing you can do now is to try other shortcuts and see if they work and it is just the Google location setting.
Click to expand...
Click to collapse
That works:
public void showClick_backup_restore_settings(View view) {
Intent intent = showBackupRestoreSettings();
startActivity(intent);
}
public static Intent showBackupRestoreSettings() {
Intent intent = new Intent(Settings.ACTION_PRIVACY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
return intent;
}
and that works too:
public void showClick_google_apps_location_settings(View view) {
PackageManager packageManager = getPackageManager();
String packageName = ("com.dozingcatsoftware.asciicam");
try {
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if(null != intent) {
startActivity(intent);
}
}
catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
-----
while this doesn't work:
public void showClick_google_apps_location_settings(View view) {
PackageManager packageManager = getPackageManager();
String packageName = ("com.google.android.location.settings.GoogleLocationSettingsActivity");
try {
Intent intent = packageManager.getLaunchIntentForPackage(packageName);
if(null != intent) {
startActivity(intent);
}
}
catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
and this doesn't work either:
public void showClick_google_apps_location_settings(View view) {
Intent intent = showGoogleAppsLocationSettings();
startActivity(intent);
}
public static Intent showGoogleAppsLocationSettings() {
Intent intent = new Intent("com.google.android.location.settings.GoogleLocationSettingsActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
return intent;
}

Lockscreen Lifecycle Question

Hey!
Is it normal that when the Lockscreen is toggled by the Power button, that onResume is called immediately after onPause?
Because I want to stop the Background music during the lock screen and at the moment it only pauses with home button because I resume it in onResume...
Thx for your help!
I think you can capture the keydown event to decide this.
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME)//and others KEYCODE_POWER ...
{
//pause your job
}
}

Categories

Resources