开发者

How to make activity always on top on android?

i make a lock screen application that prevent other people to access the device when it's locked. i have an activity called lockscreen activity. here's the code:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class LockScreen extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lockscreen);
    }

    protected void onPause() {
            super.onPause();
            // it will display a lock screen again when the home button is pressed
            Intent myIntent = new Intent(LockScreen.this, LockScreen.class);
            myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getApplication().startActivity(myIntent);
        }
    }

that code is used for relaunch the lockscreen activity when home button pressed, so that device can still locked. if i press the home button and didn't tap any application, it will show that lockscreen acti开发者_如何学编程vity again within 5 second (based on android issue), but if i tap any application (eg: setting or messages) my lockscreen activity will shown after i close that application (the setting or messages is on the top and cover my lockscreen activity) so the device still can be accessed. has anyone know how to make an activity stay on top for minimize the access from unauthorized people? thanks..


I'm not so sure that is possible to make an app stay on top always like that. And what are you going to do when they push the home button? Or what if they run Cyanogen and hold the back button to "kill" the app? It doesn't sound like an effective way to make a lock screen. Perhaps you can look at some of these other questions that are kinda similar. I just think that there must be a better way to implement a lock screen app.

Source of Android's lock screen

This link tells you how to find the android source code online Where can I find Android source code online?

And this is the actual link of where the LockScreen.java is located https://github.com/android/platform_frameworks_policies_base/blob/master/phone/com/android/internal/policy/impl/LockScreen.java

Good luck!


I have come across this problem long before, then I finally found out it's impossible to do so unless you modify framework.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜