मुझे साझा करने के लिए कैसे मैं एक पीछे की ओर संगत समाधान कर दिया की अनुमति दें।
यदि खाते से जुड़े पासकोड थे तो मैंने लॉन्च पर अपने ऐप को लॉक कर दिया था। पूरा होने के लिए, मुझे उन परिस्थितियों को संभालने की आवश्यकता थी जहां अन्य अनुप्रयोग (होम गतिविधि समेत) एन-मिनट के लिए लेते हैं।
मैं बेसएक्टिविटी बनाने के लिए समाप्त हुआ कि मेरी सभी गतिविधियां विस्तारित हैं।
// DataOperations is a singleton class I have been using for other purposes.
/* It is exists the entire run time of the app
and knows which activity was last displayed on screen.
This base class will set triggeredOnPause to true if the activity before
"pausing" because of actions triggered within my activity. Then when the
activity is paused and triggeredOnPause is false, I know the application
is losing focus.
There are situations where an activity will start a different application
with an intent. In these situations (very few of them) I went into those
activities and hard-coded these lines right before leaving my application
DataOperations datao = DataOperations.sharedDataOperations();
datao.lostFocusDate = new Date();
*/
import java.util.Date;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
public class BaseActivity extends Activity {
public boolean triggeredOnPause;
@Override
public void onResume(){
super.onResume();
DataOperations datao = DataOperations.sharedDataOperations();
if (datao.lostFocusDate != null) {
Date now = new Date();
long now_ms = now.getTime();
long lost_focus_ms = datao.lostFocusDate.getTime();
int minutesPassed = (int) (now_ms-lost_focus_ms)/(60000);
if (minutesPassed >= 1) {
datao.displayLock();
}
datao.lostFocusDate = null;
}
triggeredOnPause = false;
}
@Override
public void onPause(){
if (triggeredOnPause == false){
DataOperations datao = DataOperations.sharedDataOperations();
datao.lostFocusDate = new Date();
}
super.onPause();
}
@Override
public void startActivity(Intent intent)
{
triggeredOnPause = true;
super.startActivity(intent);
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
triggeredOnPause = true;
super.startActivityForResult(intent, requestCode);
}
}
आप इस समाधान का उपयोग और मुसीबत मेरी DataOperations वर्ग के बराबर लागू करने जा रहे हैं, तो टिप्पणी और मैं आवश्यक कोड पोस्ट कर सकते हैं कृपया।
स्रोत
2012-01-14 00:23:51
धन्यवाद, अब मेरे पास कहीं शुरू करने के लिए है। –