Android生命周期 - 如何确保始终调用一个方法?

时间:2017-07-28 09:39:59

标签: android

我必须做些什么才能确保应用程序始终初始化,即使用户或操作系统已将其杀死?

MyAlarmReceiver.onReceive()

如果操作系统调用MyBroadcastReceiver.onReceive()init() ...如何自动调用MyAlarmReceiver.onReceive()而不将其作为MyBroadcastReceiver.onReceive() <!-- PREVIEW DATA --> <!-- load the JS files in the right order --> <!-- sortable plugin for sorting/rearranging initial preview --> <script src="/path/to/js/plugins/sortable.min.js"></script> <!-- purify plugin for safe rendering HTML content in preview --> <script src="/path/to/js/plugins/purify.min.js"></script> <script src="/path/to/js/fileinput.js"></script> <script> $("#userfiles").fileinput({ 'dropZoneEnabled': true, 'maxFileCount': totalcount, 'showUpload': false, 'browseLabel': "Click Here or Drag & Drop Images Here", 'browseIcon': "<i class=\"glyphicon glyphicon-picture\"></i> ", 'validateInitialCount': true, 'allowedFileExtensions': ["jpg", "png", "gif", "jpeg"], 'showCaption': true, 'showPreview': true, 'showRemove': true, uploadUrl: "/file-upload-batch/1", uploadAsync: false, minFileCount: 2, maxFileCount: 5, overwriteInitial: false, initialPreviewAsData: true, // identify if you are sending preview data only and not the raw markup initialPreviewFileType: 'image' // image is the default and can be overridden in initialPreviewConfig. see the docs (http://plugins.krajee.com/file-preview-management-demo) }).on('filesorted', function(e, params) { console.log('File sorted params', params); }).on('fileuploaded', function(e, params) { console.log('File uploaded params', params); }); </script> 中的第一个语句1}}等等?

2 个答案:

答案 0 :(得分:2)

创建一个扩展Application的类并将该语句放在onCreate方法中 参考:C++/CLI wrapper for native C++ to use as reference in C#

答案 1 :(得分:0)

你可以在你的类中添加一个静态块,这个代码块将在这个类由ClassLoader加载时执行,这意味着任何使用这个类都会导致ClassLoader将这个类加载到内存中

public class Test extends BroadcastReceiver{
    static{
         //do something
    }
}